Hello everyone,
I have a javascript function with the following code in one of my ASPs. I have a set of fields, and that is what the for loop is for. I enter values in either all or some of the fields in this set. The for loop here adds all those values and returns the total. The problem is that when I have the following set of values, 8.51, 0, 10.00.....my total turns out to be 18.50 and not 18.51.
To figure out what the issue was, I put an alert statement after everytime the total is done(I have 3 fields in this case). I found that the total after first looping is 8.51, after second is 8.51 and total after the third and the final looping is 18.5099999999998.
If I remove the parseFloat function, and add just the values, I get the right answer. What is wrong with parseFloast function? Any help would be appreciated.
for (i=0; i<=totalfields-1;i++)
{
j = "txt_Fee_" + sABNCode + "_" + i;
k = "txt_PatResponsibility_"+ sABNCode + "_" + i;
if (!eval("document.CheckCodes." + j + ".disabled")){
if (eval("document.CheckCodes." + k + ".value") != "**" )
{
x = eval("document.CheckCodes." + k + ".value");
if (eval("document.CheckCodes." + k + ".value")== "")
{
x = 0;
}
else
{
x=x.replace(",", "");
}
total += parseFloat(x.valueOf());
alert('tot='+ total);
}
}
}
Thank you in advance.
I have a javascript function with the following code in one of my ASPs. I have a set of fields, and that is what the for loop is for. I enter values in either all or some of the fields in this set. The for loop here adds all those values and returns the total. The problem is that when I have the following set of values, 8.51, 0, 10.00.....my total turns out to be 18.50 and not 18.51.
To figure out what the issue was, I put an alert statement after everytime the total is done(I have 3 fields in this case). I found that the total after first looping is 8.51, after second is 8.51 and total after the third and the final looping is 18.5099999999998.
If I remove the parseFloat function, and add just the values, I get the right answer. What is wrong with parseFloast function? Any help would be appreciated.
for (i=0; i<=totalfields-1;i++)
{
j = "txt_Fee_" + sABNCode + "_" + i;
k = "txt_PatResponsibility_"+ sABNCode + "_" + i;
if (!eval("document.CheckCodes." + j + ".disabled")){
if (eval("document.CheckCodes." + k + ".value") != "**" )
{
x = eval("document.CheckCodes." + k + ".value");
if (eval("document.CheckCodes." + k + ".value")== "")
{
x = 0;
}
else
{
x=x.replace(",", "");
}
total += parseFloat(x.valueOf());
alert('tot='+ total);
}
}
}
Thank you in advance.