Possible Duplicate:
Is JavaScript's Math broken?
when i subtract 6.4-1.6 i am getting the answer as 4.800000000000001 in JS, but i need as 4.8 without using toFixed(), toPrecision() and Math.round(). any idea???
Thanks,
crystal
Possible Duplicate:
Is JavaScript's Math broken?
when i subtract 6.4-1.6 i am getting the answer as 4.800000000000001 in JS, but i need as 4.8 without using toFixed(), toPrecision() and Math.round(). any idea???
Thanks,
crystal
Convert to integers before doing the subtraction to avoid problems with floating point arithmetic:
(6.4 * 10 - 1.6 * 10) / 10
See What Every Programmer Should Know About Floating-Point Arithmetic
This is a well-known limitation of IEEE 754 floating point numbers. See How to deal with floating point number precision in JavaScript? for solutions.