167
stack
7y

Welcome to JavaScript where
Number.isInteger(0.9999999999999999) is false and
Number.isInteger(0.99999999999999999) is true

Comments
  • 28
    The problem it's not javascript itself, but it's the limitation of floating point variable with representation error in decimal base.

    So 0.99999999999999999 is rounded to 1
  • 3
    As far as I know that is a problem with Math itself: http://relativelyinteresting.com/do...
  • 10
    Literally "close enough"? ;)
  • 8
    var a = 1;
    a=a/3; //a: 0.3333333...
    a=a*3; //a: 0.9999999...
    Now tell me, is "a" an integer or a decimal?
  • 1
  • 5
    Math tells us that 0.(9) = 1, check on your calculator.

    Do you know why?
    1/9 = 0.(1)
    2/9 = 0.(2)
    3/9 = 0.(3)
    ...
    9/9 = 1 = 0.(9)

    Isn't that interesting?
  • 0
    Math is broken.
  • 5
    @adampisula The real proof is

    x = 0.(9)
    10x = 9.(9)
    10x - x = 9x = 9.(9) - 0.(9) = 9
    x = 1
  • 1
    Holy shit my mind has been blown by all these proofs 😱
  • 0
    @BingBangTheory Actually it's the same, but you're right!
  • 0
    I think it has something to do with our base10 decimal system vs calculator/machine base2 (binary) repesentation of base10 number. So "close enough" is as acurate as is possible. But javascript does have some odd quirks lol.
Add Comment