0

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?

Mido
  • 41
  • 1
  • 4

1 Answers1

0

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 ); 
Ala Eddine JEBALI
  • 7,033
  • 6
  • 46
  • 65