How to sum two or more currency values?

function onSubmit() {

var Price1 =parseDecimal(g_form.getValue(‘u_price’)); // Call parseDecimal function
var Price2 =parseDecimal(g_form.getValue(‘u_price_2’));// Call parseDecimal function
var Total = Price1 + Price2 ;
g_form.setValue(‘u_total’,Total);//populate total field by the sum of Price1 and Price2

}

function parseDecimal(d) {

// Remove currency and any potential any undesirable character
d=d.replace(/[a-zA-Z\!\@\#\$\%\^\&\*\(\)\_\+\-\=\{\}\|\[\]\\\:\”\;’\\?\,\/\~\`]/g,””);

// Loop through the currency and replace the comma
while (d.indexOf(“,”) != d.lastIndexOf(“,”))
d=d.replace(/\./,””);

return parseFloat(d);

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s