-4

Why javascript counted wrong?

console.log(3*9.7)    // =29.099999999999998?
console.log(3*97/10) // = 29.1

1 Answers1

0

this is how Javascript's floating point arithmetic works. If you would like to know more how to avoid this I would recommend checking out this link. How to deal with floating point number precision in JavaScript?

Community
  • 1
  • 1
Derek Joseph Olson
  • 738
  • 1
  • 7
  • 22