china-unit-num
v1.0.2
Published
将阿拉伯数字转成带中文单位的数字,比如**100**转成**1百**
Downloads
5
Readme
china-unit-num
将阿拉伯数字转成带中文单位的数字,比如100转成1百
引入
直接使用
<script src="path/to/china-unit-num.min.js"></script>
commonjs
const chinaUnitNum = require('china-unit-num')
amd
require(['china-unit-num'], function (chinaUnitNum) {
// code
})
usage
chinaUnitNum(100) // => 1百
chinaUnitNum(1000) // => 1千
单位
支持['百', '千', '万', '百万', '千万', '亿']
单位
可以使用options
的ignore
选项忽略部分单位
chinaUnitNum(100, { ignore: ['百'] }) // => 100
chinaUnitNum(1000, { ignore: ['百', '千'] }) // => 1000
函数的定义见下面,支持options参数进行一些简单配置
function chinaUnitNum(num: number, options: object): string | number
options
- decimal
数字部分保留的小数位
,默认为2
- ignore
忽略某些单位的转换,为数组类型的值
,可以是单位的中文名组成的数组
,也可以是['百', '千', '万', '百万', '千万', '亿']
对应单位的下标组成的数组;比如[0, 2]
表示忽略['百', '万']