Did you ever think of (0.1 + 0.2 == 0.3) is false?
An interesting article When You Can’t Count On Your Numbers by Douglas Crockford mentioned the above operation will return false in Javascript.
More interestingly, if you try to print out the result of 0.1 + 0.2, the answer is: 0.30000000000000004.
Leons Petrazickis explains in the post comments the strange behavior:
It comes from 0.3 being a non-terminating decimal in binary, and so having to be rounded to 0.30000000000000004 for storage
I hope I will never need to use JavaScript to do a financial application.
no comments
RSS / trackback