1.0.8 • Published 3 years ago

cardinal-number v1.0.8

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

Introduce

Convert numbers to cardinal numbers, or amount description

API

covert

paramsdescriptiontypedefault
numnumber to be convertednumber
formatAmountconvert value to amount formatboolean | Functiontrue

locale

paramsdescriptiontypedefault
localeconvert lanugagezh | es | enzh

Usage

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

Support language

  • Chinese
  • Spanish
  • English

Test

File% Stmts% Branch% Funcs% LinesUncovered Line #s
en.ts10096.8810010061
es.ts10093.7510010061,77
zh.ts10096.8810010045
1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago