函数: toThousands()
ts
function toThousands(num): string;定义于: common.ts:212
将数字格式化为千分位字符串。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
num | string | number | 数字,或可被 Number() 转为数字的字符串 |
返回值
string
千分位字符串;无法转为有效数字(如 NaN、非数字字符串)时返回 ''
备注
使用 toLocaleString('en-US') 生成,故千位分隔符为逗号 ,、小数点为 .;最多保留 20 位小数。
示例
ts
toThousands(1234567) // => '1,234,567'
toThousands(1234567.89) // => '1,234,567.89'
toThousands(-1000) // => '-1,000'
toThousands('abc') // => ''