Format the sum of two currency fields

Sean Hamilton1
Tera Contributor

Hi,

I have two onChange client scripts, one for the var "hardware_cost" and the secong for "installation_config_cost"  and they sum to a third field.  I can't get the sum mfield to properly format as US currency, with dollar signs, comma's and decimals.  Here are the Scripts:

 

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

//Type appropriate comment here, and begin script below
var value1 = g_form.getValue('hardware_cost').replace(/\D/g,'');
var value2 = g_form.getValue('installation_config_cost').replace(/\D/g,'');

var sum = parseFloat(value1) + parseFloat(value2);

g_form.setValue('onetime_cost_total', sum);

 

Here is what it returns:  

SeanHamilton1_0-1746474970474.png

How can I format the sum which is the "Onetime Cost Total."  Thanks!

7 REPLIES 7

Can't figure it out!

@Sean Hamilton1 , did you figure it out with a simple business rule to accomplish the string formatting as a currency look?

Thank you.

Ankur Bawiskar
Tera Patron
Tera Patron

@Sean Hamilton1 

check this link

how can i calculate two currency fields? 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader