import convert, { locale } from 'cardinal-number';
// zh
// 格式化金额
console.log(convert(90009)) // 玖万零玖元整
console.log(convert(90009.9)) // 玖万零玖元玖角
// 转成大写
console.log(convert(90009, false)) // 玖万零玖
// es
locale('es')
// convert peso currency by default
console.log(convert(199.02)) // ciento noventa y nueve pesos 02/100 MN
// convert cardinal number, ignore points
console.log(convert(199.02, false)) // ciento noventa y nueve
// en
locale('en')
// convert amount format
console.log(convert(73.02)) // seventy-three and cents two only
// convert cardinal number by default
console.log(convert(73, false)) // seventy-three
// or custom convert points function
const formatPoints = (num: number): string[] => {
const points = getPoints(num)
let pointsList = getLessThanHundred(points)
if (num !== 0) {
return ['and point', ...pointsList, 'only']
}
return ['only']
}
console.log(convert(73.02, formatPoints)) // seventy-three and point two only