Rik's Ramblings

Monday, April 13, 2015

Floating Point Accuracy

Here's a warning if you're attempting to do any serious math using a web browser:

var foo = 0.1;
foo += 0.2;
console.log("0.1 + 0.2 = "+foo);


>>> 0.1 + 0.2 = 0.30000000000000004

Close enough right? Unless you're a bank, or rocket scientist that is!

But you already know this right?!

Don't blame JavaScript though, this is due to the IEEE floating point standard!
- IEEE Floating Point Standard




0 Comments:

Post a Comment



<< Home