manifold/web/lib/util/format.ts
2021-12-15 01:41:56 -06:00

19 lines
452 B
TypeScript

const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
maximumFractionDigits: 0,
minimumFractionDigits: 0,
})
export function formatMoney(amount: number) {
return 'M$ ' + formatter.format(amount).substring(1)
}
export function formatWithCommas(amount: number) {
return formatter.format(amount).substring(1)
}
export function formatPercent(zeroToOne: number) {
return Math.round(zeroToOne * 100) + '%'
}