|
hi,
I am doing some calculation in javascript. Lets say
a=25, b=161.2;
when I multiply these these in Javascript as below:
var result= parseFloat(a)*parseFloat(b);
it gives the answer 4029.99999999995.
But if you check it must give the result 4030.00.
I dont understand why javascript is doing internal manipulation to the result.
And how can I get the expected result.
If anybody knows something about this, plz do help me asap.
|
|
|
Hi
I am not a javascript expert, but one thing i noticed is that you parse "a" which contains the value of 25 as a float, and its not a floating point number. Could you just parse it as an integer! That may increase the accurracy of the calculation.
|
|
|
hi,
Thanks for replying. As you said, I have tried using parseInt() also, but the problem still exists. There might be some other solution to this problem.
|
|
|
|
|
|
|
|