When I type 4.1-0.1 into the javascript console in my browser (Chrome), or anywhere else in my code, it always returns the number 3.9999999999999996. I have also tried this in Firefox, and got the same result. I don't know if this is only my computer, or if this applies to all javascript, or if it's something simple I am overlooking. Also, sorry if this is a duplicate. I couldn't find any other situations like this, but I might not have been looking for the right thing.
Asked
Active
Viewed 43 times
1
-
2Floating point math- Several different representations of real numbers have been proposed, but by far the most widely used is the floating-point representation.1 Floating-point representations have a base (which is always assumed to be even) and a precision p. If = 10 and p = 3, then the number 0.1 is represented as 1.00 × 10-1. If = 2 and p = 24, then the decimal number 0.1 cannot be represented exactly, but is approximately 1.10011001100110011001101 × 2-4. https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html – Richard Czechowski Nov 10 '14 at 23:51
-
2I wonder if there is a regular expression that can match questions like this so we can just link to that article :) – Jason Sperske Nov 10 '14 at 23:53
-
@JasonSperske try Meta this will be good idea :) – ProllyGeek Nov 10 '14 at 23:55