From 79b1da130be50df80c7e5aeb221edc5669fc211e Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 13 Jul 2020 07:28:56 -0400 Subject: [PATCH] Normalize formatUnits to simplified decimals. --- packages/units/src.ts/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/units/src.ts/index.ts b/packages/units/src.ts/index.ts index 92d5b4867d..f4ea33edfe 100644 --- a/packages/units/src.ts/index.ts +++ b/packages/units/src.ts/index.ts @@ -42,6 +42,9 @@ export function commify(value: string | number): string { let suffix = ""; if (comps.length === 2) { suffix = "." + (comps[1] || "0"); } + while (suffix.length > 2 && suffix[suffix.length - 1] === "0") { + suffix = suffix.substring(0, suffix.length - 1); + } const formatted = []; while (whole.length) {