How to add a $ symbol as prefix in a variable ?

Beast
Tera Contributor

I have a variable named amount in my record producer. After adding the value to the variable i want to add a $ symbol infront of the value. 

EG : If I enter 2000 , I want $2000.

I tried onChange client script but it is not worked as expected.

 

Please help

Thanks

1 ACCEPTED SOLUTION

Mark Manders
Tera Patron

Does this help?

function FormatPrice(varName, strValue) {
   //varName is the variable name
   //strValue is the entered value of the Single Line Text variable
 
   var xNum = Number(strValue.replace(/[^0-9.]/g, "")).toFixed(2);
   var xStr = xNum.toString();
   xStr = '$' + xStr.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
   g_form.setValue(varName, xStr);
   return;
}

This function is then called on the OnChange catalog client script for the cost variable

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   FormatPrice('cost', newValue);
   return;
}

If my answer helped you in any way, please then mark it as helpful.

Mark

View solution in original post

7 REPLIES 7

Mark Manders
Tera Patron

Does this help?

function FormatPrice(varName, strValue) {
   //varName is the variable name
   //strValue is the entered value of the Single Line Text variable
 
   var xNum = Number(strValue.replace(/[^0-9.]/g, "")).toFixed(2);
   var xStr = xNum.toString();
   xStr = '$' + xStr.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
   g_form.setValue(varName, xStr);
   return;
}

This function is then called on the OnChange catalog client script for the cost variable

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   FormatPrice('cost', newValue);
   return;
}

If my answer helped you in any way, please then mark it as helpful.

Mark

Thanks.. Its Working as expected

Mohith Devatte
Tera Sage

hello @Beast ,

you can do this if its a string field

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var str = '$'+newValue;
g_form.setValue('your_cost_field',str);
}

PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU

find_real_file.png

This is the result. Getting lots of $ symbol