Decimal Subtraction problems in javascript

javascript

Solution

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

Problem

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

Original source

Related problems