Skip to content

Commit

Permalink
Merge pull request #146 from terraswap/feat/142/dashboard
Browse files Browse the repository at this point in the history
feat: thousand separator
  • Loading branch information
JoowonYun authored Nov 30, 2022
2 parents dd3f9f2 + ecf8074 commit f2a6eef
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/libs/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ 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)
const r = unit % 3
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))
}

0 comments on commit f2a6eef

Please sign in to comment.