mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2025-10-27 16:01:07 -04:00
fix currency filter rounding
This commit is contained in:
@ -1,9 +1,11 @@
|
|||||||
export function formatCurrency(val, digits = 2) {
|
export function formatCurrency(val, digits = 2) {
|
||||||
if (val !== null) {
|
if (val !== null) {
|
||||||
const x = parseFloat(val);
|
let x = parseFloat(val);
|
||||||
if (Number.isNaN(x)) {
|
if (Number.isNaN(x)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
const decimalLimiter = 10 ** digits;
|
||||||
|
x = Math.round(x * decimalLimiter) / decimalLimiter;
|
||||||
const parts = x.toFixed(digits).split('.');
|
const parts = x.toFixed(digits).split('.');
|
||||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
|
||||||
return parts.join('.');
|
return parts.join('.');
|
||||||
|
|||||||
Reference in New Issue
Block a user