Expand my Community achievements bar.

Converting string values into integers and adding them together.

Avatar

Level 2

Hello,

I need some help, I'm working with a form where we pull in values into a text field in currency format (ex. $12,345.67).  This form also has some boxes that are user entered, and I need to be able to add the values that we pull in as well as the other user entered values into another "total" field.  It looks like I need to take the string that gets pulled in, and convert it to a raw integer value and then have it add all of the values into another field.  I'm trying to do this with javascript.

any help would be appreciated.

ex.

Selling price  (pulled in automatically)

+ add ons (entered by user)

+ additional fee (entered by user)

- rebates (pulled in automatically)

+ taxes (pulled in automaticall)

-----------------------------

= total

Thanks!

1 Reply

Avatar

Level 10

Hi,

Can you pull in the information without the currency and then use a numeric field (with a currency pattern)? It would be the best approach.

If not, then you will need to strip out all non-numeric characters (except the decimal point).

I can't share a solution we developed for a client, but I can give a direction:

This in the calculate event of the Total field:

var sellPrice, cleanPrice;

if (sellingPrice.rawValue !== null) {

    sellPrice = sellingPrice.rawValue.replace(/[^0-9.]+/g, "");

    cleanPrice = Number(sellPrice);

}

this.rawValue = cleanPrice;

Hopefully you can extend this,

Niall