From d2a2dec9a1d0b2f200258b9268ea2edab555b181 Mon Sep 17 00:00:00 2001 From: maro Date: Mon, 28 Nov 2022 12:07:55 +0900 Subject: [PATCH] feat: thousand separator --- src/libs/parse.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/parse.ts b/src/libs/parse.ts index 3c9bc509..d5293d9d 100644 --- a/src/libs/parse.ts +++ b/src/libs/parse.ts @@ -167,6 +167,11 @@ export const toAmount = (value: string, contract_addr?: string) => { return value ? new BigNumber(value).times(e).integerValue().toString() : "0" } +export const formatNumber = (num: number | string) => { + const numberFormatter = Intl.NumberFormat("en-US") + return numberFormatter.format(Number(num)) +} + export const formatMoney = (num: number, fix = 2) => { const units = ["M", "B", "T", "Q"] const unit = Math.floor((num / 1.0e1).toFixed(0).toString().length) @@ -174,6 +179,6 @@ export const formatMoney = (num: number, fix = 2) => { const x = Math.abs(Number(num)) / Number(Number("1.0e+" + (unit - r)).toFixed(2)) return units[Math.floor(unit / 3) - 2] - ? x.toFixed(fix) + units[Math.floor(unit / 3) - 2] - : num.toFixed(fix) + ? formatNumber(x.toFixed(fix)) + units[Math.floor(unit / 3) - 2] + : formatNumber(num.toFixed(fix)) }