Convert numbers into Japanese rank format (e.g. 123455 => 12_万_3455)
inspired from number-to-chinise-words
npm install jp-numerals
Or,
yarn add jp-numerals
const formatter = require('jp-numerals')
// or import { numerals } from 'jp-numerals'
const n = formatter.numerals(123456789)
n.toString()
// => returns
'1億2345万6789'
n.toTuples()
// => returns
[
[1, '億'],
[2345, '万'],
[6789, '']
]
n.toNumeralObjs()
// => returns
[
{ unit: 2, character: '億', rank: 2, digits: 1 },
{ unit: 1, character: '万', rank: 1, digits: 2345 },
{ unit: 0, character: '', rank: 0, digits: 6789 }
]
n.toNumerals()
// => returns
[
Numeral { raw: 123456789, unit: 2 },
Numeral { raw: 123456789, unit: 1 },
NumeralZero { raw: 123456789, unit: 0 }
]
- round: : (base: JpNumeralUnit) => Numerals
import {numerals} from 'jp-numerals';
const n = numerals(12_3456_7890)
n.round(JpNumeralUnit.億).toString()
// => returns
'12億'
- sign: () => Sign
- toSignedNumerals: () => [Sign, Numeral[]]
- toSignedTuples: () => [Sign, [number, string][]]
- toSignedNumeralObjs: () => [Sign, NumeralObj[]]
- toSignedString: () => string
import {numerals} from 'jp-numerals';
const n = numerals(-123456789)
n.sign()
// => returns -1
n.toSignedString()
// => returns '-1億2345万6789'
n.toSignedNumeralObjs()
// => returns
[
-1,
[
{ unit: 2, character: '億', rank: 2, digits: 1 },
{ unit: 1, character: '万', rank: 1, digits: 2345 },
{ unit: 0, character: '', rank: 0, digits: 6789 }
]
]
npm test
npm run test:watch
npm run test:prod
Do not use regular git commit
for semantic release.
Instead:
npm run commit
This library is based on typescript-library-starter