0

var t = 0.2 + 0.3
console.log(t);

function myFunction() {
  var x = 0.2 + 0.1;
  console.log(x);
}
<button onclick="myFunction()">Try it</button>

Output: 0.5

After clicking button output is: 0.30000000000000004

I'm curious why it behave differently inside the function and outside the function and also why precision is so big?

George
  • 6,630
  • 2
  • 29
  • 36
freeMAN
  • 15
  • 4

0 Answers0