0

enter image description here

Can someone please explain the above behavior?

itaied
  • 119
  • 1
  • 1
  • 6
  • JS adopted the standard IEEE 754 like most of the programming languages. You can read more about that representation and representational errors on the internet, for example here https://books.google.it/books?id=PXa2bby0oQ0C&pg=PA105&dq=douglas+crockford+javascript+good+parts+dollar+values+can+be+converted&rview=1&cd=1&redir_esc=y&hl=it#v=onepage&q&f=false and here https://www.w3schools.com/js/js_numbers.asp#:~:text=JavaScript%20Numbers%20are%20Always%2064%2Dbit%20Floating%20Point&text=JavaScript%20numbers%20are%20always%20stored,the%20international%20IEEE%20754%20standard – r00ta Jan 05 '23 at 15:18
  • 1
    Short answer: It's *binary* floating point, not decimal, which ends up meaning that there's a different set of numbers that can't be represented exactly. We all know that in base 10, the fraction 1/3 cannot be represented exactly. Well, in base 2, it turns out that 1/10 (decimal 0.1) can't be represented exactly, either. Nor can 19.9. (The fact that `12.9*100` worked for you is sort of an accident.) – Steve Summit Jan 05 '23 at 15:41

0 Answers0