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:
I also have a CurrentTotal field which is the sum of CurrentYearly and CurrentOvertime, set in the custom calculation script for CurrentTotal as:
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.
The value is treated as a string instead of a number, so it is just being
concatenated to the other value, instead of added to it.
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):