From 13de5de24d1a2996505befc8dd2d91a91f0cdf12 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Sat, 21 May 2022 16:28:47 -0700 Subject: [PATCH] Default large nums to 2 sigfigs --- common/util/format.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/util/format.ts b/common/util/format.ts index c68f319e..10b7c1de 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -30,17 +30,17 @@ export function formatPercent(zeroToOne: number) { } // Eg 1234567.89 => 1.23M; 5678 => 5.68K -export function formatLargeNumber(num: number, sigfigs = 3): string { +export function formatLargeNumber(num: number, sigfigs = 2): string { const absNum = Math.abs(num) if (absNum < 1000) { - return num.toPrecision(sigfigs) + return '' + Number(num.toPrecision(sigfigs)) } const suffix = ['', 'K', 'M', 'B', 'T', 'Q'] const suffixIdx = Math.floor(Math.log10(absNum) / 3) const suffixStr = suffix[suffixIdx] const numStr = (num / Math.pow(10, 3 * suffixIdx)).toPrecision(sigfigs) - return `${numStr}${suffixStr}` + return `${Number(numStr)}${suffixStr}` } export function toCamelCase(words: string) {