formatNumber(number
, decimals?
, decPoint?
, thousandsSep?
, roundTag?
): string
格式化数字、金额、千分位、保留几位小数、舍入舍去
Name | Type | Default value | Description |
---|---|---|---|
number |
string | number |
undefined |
要格式化的数字或数字字符串 |
decimals? |
number |
2 |
保留几位小数,默认为2,范围0-20 |
decPoint? |
string |
'.' |
小数点符号,默认为'.' |
thousandsSep? |
string |
',' |
千分位符号,默认为',' |
roundTag? |
"ceil" | "floor" | "round" |
'ceil' |
舍入方式: 'ceil'向上取整, 'floor'向下取整, 'round'四舍五入 |
string
格式化后的数字字符串
Description
提供数字格式化功能,支持千分位分隔、小数位控制、舍入方式选择
Since
1.0.7
Throws
当输入参数类型不正确时抛出
Throws
当decimals超出0-20范围时抛出
Example
Example