UnisKB/ui/src/utils/utils.ts

9 lines
281 B
TypeScript
Raw Normal View History

2023-11-03 08:12:57 +00:00
function toThousands(num: any) {
return num.toString().replace(/\d+/, function (n: any) {
return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
})
}
export function numberFormat(num: number) {
return num < 1000 ? toThousands(num) : toThousands((num / 1000).toFixed(1)) + 'k'
}