number-to-text
is a regular expression driven number to text converter (no mathematical operation used). supported languagesen-us
(US English),en-in
(Indian English),de
(German),tr
(Turkish),id
(Indonesian)
npm install number-to-text --save
bower install number-to-text --save
const numberToText = require('number-to-text')
require('number-to-text/converters/en-us');
numberToText.convertToText(12346)
numberToText.convertToText("12346")
<script src="bower_components/dist/number-to-text.js"></script>
<!-- creates numberToText object on window -->
<script>
console.log(numberToText.convertToText(123456));
</script>
Arguments
num
- a string or number.options
language
- Default:en-us
- possible Values :en-us
, 'en-in', 'de', 'tr'separator
- Default:,
for (en-us and en-in)case
- Default:titleCase
- possible Values :"titleCase" , "lowerCase" , "upperCase"
for (en-us and en-in)
Examples
const numberToText = require('number-to-text')
require('number-to-text/converters/en-us'); // load converter
numberToText.convertToText('123456')
//One Hundred Twenty Three Thousand, Four Hundred Fifty Six
numberToText.convertToText(123456)
//One Hundred Twenty Three Thousand, Four Hundred Fifty Six
numberToText.convertToText(123456,{case:"lowerCase"})
//one hundred twenty three thousand, four hundred fifty six
numberToText.convertToText(123456,{case:"upperCase"})
//ONE HUNDRED TWENTY THREE THOUSAND, FOUR HUNDRED FIFTY SIX
numberToText.convertToText('123456',{separator : '', case:"upperCase"})
//ONE HUNDRED TWENTY THREE THOUSAND FOUR HUNDRED FIFTY SIX
function is used to implement your own language converter.
Arguments
language
- a language code.langConverter
- an object inehrited from numberToText.Converter
writing own language converter
const numberToText = require('numberToText')
class EnCustomConverter extends numberToText.Converter { // use language code as converter prefix
constructor () {
super()
numberToText.addConverter(""/*enter language name here*/, this);
}
convertToText (num, options) {
/* Implement number to text conversion logic */
}
}
module.exports = new EnCustomConverter()
npm test