外观
numberToChinese 数字转中文大写
约 225 字小于 1 分钟
2024-01-01
介绍
将数字转换为中文大写形式,整数部分按「元 / 万 / 亿」与「拾 / 佰 / 仟」组合,负数会以「欠」开头,常用于票据、财务等场景。
基本用法
import { numberToChinese } from '@/uni_modules/uview-unix'
console.log(numberToChinese(1234)) // '壹仟贰佰叁拾肆元'
console.log(numberToChinese(100)) // '壹佰元'
console.log(numberToChinese(-256)) // '欠贰佰伍拾陆元'
console.log(numberToChinese(12345)) // '壹万贰仟叁佰肆拾伍元'API
numberToChinese(amount: number): string
参数
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| amount | 待转换的数字,负数会添加「欠」前缀 | number | - |
返回值
string 中文大写字符串,如 壹仟贰佰叁拾肆元、欠壹佰元。
注意事项
- 传入
0时返回空字符串,不会返回「零元」。 - 传入带小数的数字时,小数部分不会输出,结果以「整」结尾;整数金额不带「整」。
