marlun78 / number-to-words Goto Github PK
View Code? Open in Web Editor NEWConverts a number to words
License: MIT License
Converts a number to words
License: MIT License
It is a shame this lib is only in english !
You should definitely implement a locale for foreign countries
I've found the issue with negative numbers:
var numberToWords = require("number-to-words")
console.log(numberToWords.toOrdinal(-11))
console.log(numberToWords.toOrdinal(-12))
console.log(numberToWords.toOrdinal(-13))
returns:
-11st
-12nd
-13rd
Have you ever seen this before? If so, Is there a way to avoid?
comma separated numbers has only the part before the first coma. What is the solution here..?
Add pluggable languages files for multi-language support.
What are your thoughts on making this a numeral.js plugin?
http://numeraljs.com/#custom-formats
Might make implementing the multiple language packs easier.
i get this error when trying to convert number to words
TypeError: Not a finite number: undefined (undefined)
at Object.j [as toWords]
Not sure how much work this would take, but a toNumber function that took in a string of cardinal numbers e.g one hundred and five
and returned it's number counterpart e.g 105
would be great
Todays API is a bit weird. Eg. numberToWords.toWordsOrdinal(2)
doesn’t read too well.
For this value 800000000000000000000000
Amount in words is coming SEVEN HUNDRED NINETY-NINE BILLION NINE HUNDRED NINETY-NINE MILLION NINE HUNDRED NINETY-NINE THOUSAND NINE HUNDRED NINETY-NINE TRILLION NINE HUNDRED NINETY-NINE BILLION NINE HUNDRED TWENTY-TWO MILLION SEVENTY-THREE THOUSAND SIX HUNDRED
Can i use declarations for it?
toWords
second optional asOrdinal
-parameter is deprecated and should be removed.
Would be great to have the option to get the words as an array so that we can construct our own joining rules easily. E.g.:
converter.toWords(9007199254740992, true); // 'true' to get return as data
Returns:
[
'nine quadrillion',
'seven trillion',
'one hundred ninety-nine billion',
'two hundred fifty-four million',
'seven hundred forty thousand',
'nine hundred',
'ninety-two'
]
Then we can do things like:
let wordsArray = converter.toWords(9007199254740992, true);
let ret1 = `There are over ${wordsArray[0]} available.`; // There are over nine quadrillion available.
or
let wordsArray = converter.toWords(1992, true);
let last = wordsArray.pop()
let ret = 'There are ' + wordsArray.join(' ') + ' and ' + last; // There are one thousand nine hundred and ninety-two
var numberToWords = require("number-to-words");
const tw = numberToWords.toWords;
[1,4,5,7].map((d) => tw(d));
[1,4,5,7].map(tw);
When the library is used with an implicit passed parameter (second example), every array element except the first is an ordinal numeral:
The result of [1,4,5,7].map((d) => tw(d));
is ["one", "four", "five", "seven"]
The result of [1,4,5,7].map(tw);
is: ["one", "fourth", "fifth", "seventh"]
Hi, I like this library.
But I am from India and we use lakhs and crores instead of millions and billions.
Can we have this option in this library.
Thanks
Hi, great module! Perhaps add an option for an 'and' word to be added in certain circumstances. Your module seems the best so far, just an idea for your really.
converter.toWords(40092); // => “forty thousand AND ninety-two”
converter.toWords(20607); // => “twenty thousand six hundred AND seven”
Thanks
Sharry
I cannot seem to manipulate a number that has been converted to a string, using string methods such as .split()
, .replace()
or .join()
.
I'm using TypeScript and React.
Example:
var numberToWords = require('number-to-words');
var id = 1526;
var idWord: string = numberToWords.toWords(id);
idWord.replace(' ', '');
console.log(idWord) // Returns 'one thousand, five hundred twenty-six' instead of the correct 'onethousand,fivehundredtwenty-six'
Converter returns ordinal numbers with wrong endings:
converter.toOrdinal(11); // => “11st”
converter.toOrdinal(12); // => “12nd”
converter.toOrdinal(13); // => “13rd”
But should be 11th, 12th, 13th.
Hi, I've converted this package to an ES6 module and cleaned it up quite a bit. Thought you may want to add a link to the readme for users that need tree shaking, etc.
Could I use with "decimal number"?
123456.789
HEllo,
Can you please enable to the possibility to remove or include the 'and '?
I could do it myself for my project I guess, but I figured other people could benefit from it if the original author publishes it on npm. It should be as simple as adding a bool to the toWords(number,includeAnd) function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.