Here's the problem... A user enters a total amount and then breaks down the total amount by budget account numbers. The total amount and summed amounts by budget numbers must match.
i.e. Stipend Total = 982.79
bgt #1 = 245.88
bgt #2 = 405.30
bgt #3 = 331.61
bgts 1,2,3 = 982.79 but program returns
Stipend total = 982.79
Bgt amts totals = 982.790000000000001
Here is how I have tried to fix this...
I have converted the Bgt amount totals and the original stipend amount to .toFixed(2) amounts and then compare the two amounts.
The program still returns "Amounts don't match"
Here is sample code:
if (whatever)
{
var n1 = parseFloat(theForm.StipendTotal.value);
alert("n1 = " + n1);
var n4 = n1.toFixed(2);
alert("n4 = " + n4); //returns 982.79
var n2 = parseFloat(theForm.BgtAmt1.value) + parseFloat(theForm.BgtAmt2.value) + parseFloat(theForm.BgtAmt3.value) + parseFloat(theForm.BgtAmt4.value) + parseFloat(theForm.BgtAmt5.value)
alert("n2 = " + n2);
var n3 = n2.toFixed(2);
alert ("n3 = " + n3); //returns 982.79
if (n3 != n4); //Here is the comparison of the two converted variables. Based on my alerts, both numbers match, but this error is still returned
{
alert("Stipend Total is: " + theForm.StipendTotal.value + "\rBudget Amounts Total: " + parseFloat(parseFloat(theForm.BgtAmt1.value) + parseFloat(theForm.BgtAmt2.value) + parseFloat(theForm.BgtAmt3.value) + parseFloat(theForm.BgtAmt4.value) + parseFloat(theForm.BgtAmt5.value)) + "\r\rThey must match.");
return (false);
}
}
My toFixed alerts both return 982.79. Does anyone know why these don't appear to be a match?
Any help would be appreciated.
Thank you,
Patrice
i.e. Stipend Total = 982.79
bgt #1 = 245.88
bgt #2 = 405.30
bgt #3 = 331.61
bgts 1,2,3 = 982.79 but program returns
Stipend total = 982.79
Bgt amts totals = 982.790000000000001
Here is how I have tried to fix this...
I have converted the Bgt amount totals and the original stipend amount to .toFixed(2) amounts and then compare the two amounts.
The program still returns "Amounts don't match"
Here is sample code:
if (whatever)
{
var n1 = parseFloat(theForm.StipendTotal.value);
alert("n1 = " + n1);
var n4 = n1.toFixed(2);
alert("n4 = " + n4); //returns 982.79
var n2 = parseFloat(theForm.BgtAmt1.value) + parseFloat(theForm.BgtAmt2.value) + parseFloat(theForm.BgtAmt3.value) + parseFloat(theForm.BgtAmt4.value) + parseFloat(theForm.BgtAmt5.value)
alert("n2 = " + n2);
var n3 = n2.toFixed(2);
alert ("n3 = " + n3); //returns 982.79
if (n3 != n4); //Here is the comparison of the two converted variables. Based on my alerts, both numbers match, but this error is still returned
{
alert("Stipend Total is: " + theForm.StipendTotal.value + "\rBudget Amounts Total: " + parseFloat(parseFloat(theForm.BgtAmt1.value) + parseFloat(theForm.BgtAmt2.value) + parseFloat(theForm.BgtAmt3.value) + parseFloat(theForm.BgtAmt4.value) + parseFloat(theForm.BgtAmt5.value)) + "\r\rThey must match.");
return (false);
}
}
My toFixed alerts both return 982.79. Does anyone know why these don't appear to be a match?
Any help would be appreciated.
Thank you,
Patrice