I am trying to add two numbers in JavaScript, but the result is inexact. This my example:
var x = 11.12, y = 11.07;
console.log(x + y); // the result is 22.189999999999998 but the real result is 22.19
Any solution for this?
I am trying to add two numbers in JavaScript, but the result is inexact. This my example:
var x = 11.12, y = 11.07;
console.log(x + y); // the result is 22.189999999999998 but the real result is 22.19
Any solution for this?
This is what you need to do:
var x = 11.12, y = 11.07;
var result = (parseFloat(x) + parseFloat(y)).toFixed(2);
console.log( result );