Skip to content

Instantly share code, notes, and snippets.

@chieffancypants
Created October 10, 2012 01:06
Show Gist options
  • Save chieffancypants/3862532 to your computer and use it in GitHub Desktop.
Save chieffancypants/3862532 to your computer and use it in GitHub Desktop.
Floating Point Precision anomalies w/ currency
// 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