I came across an example in the book:

var x = .3 - .2; var y = .2 - .1; x == y // => false: получилисьдва разных значения! x == .1 // => false: .3-.2 не равно .1 y == .1 // => true: .2-.1 равно .1 

Explain to me the fool (I did not believe it at first, and repeated it in the Google console, and it turned out that the author is right!), But why x == .1 // => false ?

  • Well, the button accordion, learn the language and google about the representation of floating-point numbers in memory - DreamChild
  • Yes, not even a language, but in general the representation of numbers in a computer. What you need to know about floating-point arithmetic . - Nofate

1 answer 1

Most likely, there is an error of rounding numbers, so in my mozilla console:

 .3 - .2 == 0.09999999999999998 .2 - .1 == 0.1 

PS Next time you say which book and author, and let us have a more detailed question, what do you study and what does the author say.