sonic wrote:
> What is the correct way of performing this substraction in JS.
>
> var a = '29.33'; ( or 29.33 )
> var b = '0.01'; ( or 0.01 )
>
> var result = a - b;
>
> ( result = 29.319999999999996; )
>
> my result is rounded off in the way floats would round off :/
This is an inherent problem with floating-point arithmetic.
Floating-point should never be used when decimal precision is required,
such as in applications concerning money.
Use scaled integers instead. Instead of working in dollars, work in
cents. Integer arithmetic is precise.
http://www.crockford.com/javascript