Default large nums to 2 sigfigs

This commit is contained in:
Austin Chen 2022-05-21 16:28:47 -07:00
parent 1cfbd86bd0
commit 13de5de24d

View File

@ -30,17 +30,17 @@ export function formatPercent(zeroToOne: number) {
} }
// Eg 1234567.89 => 1.23M; 5678 => 5.68K // 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) const absNum = Math.abs(num)
if (absNum < 1000) { if (absNum < 1000) {
return num.toPrecision(sigfigs) return '' + Number(num.toPrecision(sigfigs))
} }
const suffix = ['', 'K', 'M', 'B', 'T', 'Q'] const suffix = ['', 'K', 'M', 'B', 'T', 'Q']
const suffixIdx = Math.floor(Math.log10(absNum) / 3) const suffixIdx = Math.floor(Math.log10(absNum) / 3)
const suffixStr = suffix[suffixIdx] const suffixStr = suffix[suffixIdx]
const numStr = (num / Math.pow(10, 3 * suffixIdx)).toPrecision(sigfigs) const numStr = (num / Math.pow(10, 3 * suffixIdx)).toPrecision(sigfigs)
return `${numStr}${suffixStr}` return `${Number(numStr)}${suffixStr}`
} }
export function toCamelCase(words: string) { export function toCamelCase(words: string) {