2 Replies Latest reply on Apr 25, 2012 6:12 PM by shiny01248

# Calculation errors when entering currency formatted numbers

I am creating a form that has several fields, all defined as numbers using currency formatting:

CurrentBase which is the monthly pay rate which the user enters

CurrentYearly which is the annual pay rate and is calculated as CurrentBase * 12 -- this is read-only

CurrentOvertime which is an estimate based on 6% of the CurrentYearly and which the user can override.

As a OnBlur event in CurrentBase I use this code:

var cYear=this.getField("CurrentYearly");

cYear.value=this.getField("CurrentBase").value* 12;

this.getField("CurrentOvertime").value=cYear.value*0.06;

I also have a CurrentTotal field which is the sum of CurrentYearly and CurrentOvertime, set in the custom calculation script for CurrentTotal as:

this.getField("CurrentTotal").value=this.getField("CurrentYearly").value+this.getField("Cu rrentOvertime").value;

Here is the problem:

If I enter a CurrentBase, such as 1234 my script correctly calculates the CurrentYearly (\$14,808.00), CurrentOvertime (\$888.48) and CurrentTotal (\$15,696.48) correctly.

Now if I override the CurrentOvertime using something like 555.00 the total calculates correctly, in this case \$15,363.00

But if I type 555. (omitting the decimal values) my CurrentTotal displays as \$14,808,555.00

This seems to be a bug.  Any thoughts on why and how to fix it.

Bob

• ###### 1. Re: Calculation errors when entering currency formatted numbers

The value is treated as a string instead of a number, so it is just being

The solution is to explicitly convert the value to a number, which can be

done in several ways. The simplest is to add a plus symbol in front of it,

like so (the brackets are not required, but they make it easier to read):

this.getField("CurrentTotal").value =

(+this.getField("CurrentYearly").value) +

(+this.getField("CurrentOvertime").value);

• ###### 2. Re: Calculation errors when entering currency formatted numbers

Thanks.  That did the trick.  Formatting doesn't type cast the variables... I thought that might be the case.  Thanks again!