What kind of mistakes? How do I fix this?
1.1 - 1 = 0.10000000000000009
1.0000001+1 = 2.0000001000000003
What kind of mistakes? How do I fix this?
1.1 - 1 = 0.10000000000000009
1.0000001+1 = 2.0000001000000003
you can solve this by using .toFixed()
method
its the floating point problem take a look here
eg:
<script>
alert((1.234567890).toFixed(2))
</script>
The javascript uses the data type float. Float numbers are never exact so do not use == when you compare the data instead use < and/or >.
From the comp.lang.javascript FAQ(which seem to be down at the moment):
ECMAScript numbers are represented in binary as IEEE-754 (IEC 559) Doubles, with a resolution of 53 bits, giving an accuracy of 15-16 decimal digits; integers up to just over 9e15
are
precise, but few decimal fractions are. Given this, arithmetic is as exact as possible, but no more. Operations on integers are exact if the true result and all intermediates are integers within that range.
In particular, non-integer results should not normally be compared for equality, and non-integer computed results commonly need rounding.