0

In my new Qt application, I used QML items. But in minus operator, javascript function does not subtract correctly.

When running this code:

console.log( "4.1 - 4 ==> " + (4.1 - 4))

the result is like this:

qml: 4.1 - 4 ==>0.09999999999999964
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
SajadBlog
  • 514
  • 2
  • 12
  • 3
    [language agnostic - Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Andreas Jun 22 '19 at 11:09
  • 3
    It's not Javascript, it's the math which is guilty. ;-) It starts with the fact that 0.1 (in decimal system) is a periodic fraction in the binary system (i.e. with an infinite number of repeating digits) which cannot be stored with a finite number of bits (except you would store it as pair of numerator and denominator). – Scheff's Cat Jun 22 '19 at 16:37

0 Answers0