From 1e2df9905455759747d1ab3a558a44250844bd27 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Fri, 30 Sep 2022 15:05:37 -0500 Subject: [PATCH] Change format money to round up if within epsilon --- common/util/format.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/util/format.ts b/common/util/format.ts index 4f123535..ee59d3e7 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -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('$', '') }