Skip to content

NumberFormat 数字格式化 ​

简介 ​

将数字格式化为指定格式,例如千分位或货币。

代码演示 ​

基础使用 ​

传递数字或字符串类型数字即可展示为千分位形式。

百分比格式 ​

设置 type="percent" 会格式化为百分比格式。

货币 ​

设置 type="currency" 展示为货币形式。

动画 ​

通过设置 animate ,每当值变更时,会从旧值滚动到新的值。

API ​

NumberFormatProps ​

属性描述类型默认值
value要展示的数值number | string-
precision小数个数number0
animate是否动画booleanfalse
duration动画持续时间,单位毫秒number1500
localesBCP 47 语言标签,详见string'zh-Hans'
type格式化样式'currency' | 'decimal' | 'percent''decimal'
currency货币类型,详见string'CNY'
before-display在格式化后的值展示前进行处理(value: string) => string-

基于 MIT 许可发布