currency.filter.js - fix edge case rounding

This commit is contained in:
Marek Fraczyk
2021-05-26 16:47:53 +03:00
parent f25f73ca3b
commit 4aaa06c3e9

View File

@ -5,7 +5,7 @@ export function formatCurrency(val, digits = 2) {
return '';
}
const decimalLimiter = 10 ** digits;
x = Math.round(x * decimalLimiter) / decimalLimiter;
x = Math.round((x + Number.EPSILON) * decimalLimiter) / decimalLimiter;
const parts = x.toFixed(digits).split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
return parts.join('.');