Change format money to round up if within epsilon

This commit is contained in:
James Grugett 2022-09-30 15:05:37 -05:00
parent 37beb584ef
commit 1e2df99054

View File

@ -8,7 +8,12 @@ const formatter = new Intl.NumberFormat('en-US', {
})
export function formatMoney(amount: number) {
const newAmount = Math.round(amount) === 0 ? 0 : Math.floor(amount) // handle -0 case
const newAmount =
// handle -0 case
Math.round(amount) === 0
? 0
: // Handle 499.9999999999999 case
Math.floor(amount + 0.00000000001 * Math.sign(amount))
return ENV_CONFIG.moneyMoniker + formatter.format(newAmount).replace('$', '')
}