Skip to content

Instantly share code, notes, and snippets.

@chieffancypants
chieffancypants / Floating Point Precision anomalies
Created October 10, 2012 01:06
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);
}
}
}