View Full Version : subtracting one number from another number

September 25th, 2012, 05:33 PM
I have two data fields that have large numbers in them. I need to subtract one number from the other. they have two decimal places. This sounds simple enough, but I can't get it to work without FP doing some wierd formatting on the numbers, that gives me 17.00 instead of 16855.36.
its like it is rounding up the first two numbers.
Here is the rule as I have it currently.

var account = StringToNumber(Field("ACCOUNT-ENDING"))
var company = StringToNumber(Field("COMPANY-ENDING"))
var total = account - company
return FormatNumber("#####.##",total)

// the numbers in the data are
//ACCOUNT-ENDING = 66,442.44
//COMPANY-ENDING = 49,587.08
//the result of this function is 17.00

any idea what I am doing wrong?

September 26th, 2012, 07:01 AM
I think the comma is throwing off the calculation. Try this:

var account = StringToNumber(Field("ACCOUNT-ENDING").replace(/,/g,""))
var company = StringToNumber(Field("COMPANY-ENDING").replace(/,/g,""))

September 28th, 2012, 08:31 AM
That worked perfectly. What does the g stand for?

thanks for your help

September 28th, 2012, 08:40 AM
the "g" makes the change globally. If the dollar amount were to contain more than 1 comma, it would remove all of them.

Glad that worked for you!