Help with currency formatting

Marcel H_
Tera Guru

I am having trouble with a script that I am trying to write to add two different currency fields together and then display the SUM in a 3rd field. Part of the issue, I think, is that once of the fields is read only and the other isn't (by design).

The fields look like the below picture on my form. I want to add Total Cost and Commission Amount together into Cost + Commission. 

find_real_file.png

The script I have is returning the following values:

  • Total Cost: 1158889
  • Commission Amount: 173833.24
  • Total: 1332722

I am using the following script in an onChange client script to calculate the amount, which is getting calculated mostly correct, I just don't get any of the commas and don't get any values after the decimal point.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	
	var tc = g_form.getValue('total_cost');
	var ca = g_form.getValue('u_commission_amount.display').replace(/,/g, "");
	//var cc = 'u_cost_commission.display';
	var total = parseInt(tc) + parseInt(ca);
g_form.setValue('u_cost_commission.display', total.toFixed(2));  
}

Is there a way I can modify my script to get the correct output into the field?

 

7 REPLIES 7

HungMiju
Mega Expert

Hi Marcel

Please try to use


var ca = parseFloat(g_form.getValue('u_commission_amount').split(";")[1].replace(/,/g, ""))

I tried a couple of different ways to replace the comma and was unsuccessful. This was exactly what I was looking for. Thank you. 

Marcel H_
Tera Guru

Thanks for the suggestion, I appreciate the response.

The script is still having issues though unfortunately. When I place alerts in my script I get back the following:

  • Total Cost = 115889
  • Commission Amount = 173833.24
  • Cost + Commission = 1332722

So currently the issue that I'm having is that Cost + Commission then displays as 1332722.00 ignoring the .24 from Commission Amount, and does not have any of the comma formatting like the other currency fields. I also noticed that when adding the Cost + Commission field to the list view, it always comes back as 0 as if the field is not actually updating with the g_form.setValue line.

find_real_file.png

please give me the script in the onchange function again

because i just tried on my site it works