Created
October 10, 2012 01:06
-
-
Save chieffancypants/3862532 to your computer and use it in GitHub Desktop.
Floating Point Precision anomalies w/ currency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Construct every 2-digit decimal and test its precision | |
for (var d = 0; d < 100; d++) { | |
for (var c = 0; c < 100; c++) { | |
if (c < 10) { c = '0' + c; } | |
var currency = parseFloat(d + '.' + c).toFixed(2); | |
if ((currency * 100) != currency.toString().replace(/\./, '')) { | |
console.log(currency * 100); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment