numbers-to-words
v2.0.0
Published
Convert numbers to words using the Indian numbering system.
Maintainers
Readme
numbers-to-words
Convert numbers to words using the Indian numbering system.
Features
- Accepts numbers, numeric strings, and comma-formatted strings
- Ignores the decimal portion and converts only the integer part
- Returns a consistent
{ status, response }object - Supports values up to
99,99,99,99,999 - Includes a separate million/billion formatter
Installation
npm install numbers-to-wordsUsage
const numbersToWords = require("numbers-to-words");
async function main() {
const indian = await numbersToWords("3,98,70,45,673");
const international = await numbersToWords.international("3,98,70,45,673");
console.log(indian);
console.log(international);
}
main();Output:
{
status: "success",
response: "Three Hundred Ninety Eight Crore Seventy Lakh Forty Five Thousand Six Hundred Seventy Three"
}
{
status: "success",
response: "Three Billion Nine Hundred Eighty Seven Million Forty Five Thousand Six Hundred Seventy Three"
}API
const indianResult = await numbersToWords(input);
const internationalResult = await numbersToWords.international(input);input may be:
- a JavaScript
number - a numeric
string - a comma-formatted numeric
string
numbersToWords(input):
- Uses the Indian numbering system
- Supports up to 11 digits
numbersToWords.international(input):
- Uses the international numbering system
- Produces
MillionandBilliongroupings - Supports up to 12 digits
Successful conversion returns:
{
status: "success",
response: "One Lakh"
}Invalid input or out-of-range values return:
{
status: "failure",
response: "Only values up to 11 digits are supported."
}Development
npm test