I have the following simple math operation.
var a = 1.12345678 + 1;
console.log(a);
which results in
2.1234567799999997
why?
I expect the result to be
2.12345678
I have the following simple math operation.
var a = 1.12345678 + 1;
console.log(a);
which results in
2.1234567799999997
why?
I expect the result to be
2.12345678
I would just recommend using +a.toFixed(8)
JavaScript uses floating point precision, which is never 100% accurate
Simple solution:
Math.round(( OPERATION ) * 1e12) / 1e12
Supports all browsers. toFixed() causes strange things to happen on IE.