currency-in-words
Convert currency or similar number formats to respective words
Installation:
npm i currency-in-words
Usage:
import { convert } from 'currency-in-words'
const result = convert('777')
const result = convert('777', { format: 'intl' }) seven
console.log('777')
console.log('1022')
console.log('1,022')
console.log('66.123')
console.log('99.11')
console.log('99.09')
console.log('100000')
console.log('100000', { format: 'int' })
Note
- Expect
NaN
when ',' is present, eg: '100,000.99' - Expect
NaN
when any invalid characters are present, eg: 10E55 - Fractional part is corrected to two places
- Decimals from .00 to .09 is ignored.
- However, visit Hacks to learn how to handle these limitations
Compatibility
Supports upto 15 digits for both indian and international systems on their integer part. A RangeError will be thrown for length beyond 15.
eg: calling convert with 100,000,000,000,000 * 10 will throw a range error
International system:
999,999,999,999,999 (1 quadrillion - 1)
Indian system:
99,99,99,99,99,99,999 (100 crore crore - 1)
Hard time passing it as a string? cast it from the source
const amount = 0.99
const result = convert(`${amount}`)
Eliminate commas
const amount = '1,000.99'
const sanitized = amount.replace(/,/, '')
Want decimal places not to be corrected? Control it from code.
const amount = '123.123'
const [dollars, cents] = amount.split('.')
const result = `${convert(dollars)}.${convert(cents)}`