Click here to Skip to main content
15,887,854 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need some help with converting numbers to a special word format.

For example, let's say I have the number 2,000, I want to convert it to two thousand. Simple enough. Now...let's say I have the number 23,000...I want to convert it to two three thousand. 15,500 would be converted to one five thousand five hundred, so on and so forth.
Posted
Updated 8-Jul-14 15:08pm
v2
Comments
Richard MacCutchan 8-Jul-14 14:27pm    
So what happens when you test it?
dutchcoffee 8-Jul-14 14:29pm    
The current code logic I have doesn't write the numbers in the format I want. For example, it will write 23,000 as "twenty-three thousand" as opposed to "two three thousand".
Richard MacCutchan 8-Jul-14 14:32pm    
Then you should change the logic for numbers in the 10s, 20, 30s etc., ranges.
PIEBALDconsult 8-Jul-14 15:12pm    
There are many many many many many many many many many articles just here on CodeProject that cover that.
http://www.codeproject.com/Tips/379815/Convert-Number-to-Text?msg=4244099#xx4244099xx

There are tons of examples, for example Google[^] returns:
Convert numbers to words in English and Asian format[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Jul-14 15:24pm    
5ed.
—SA
Maciej Los 8-Jul-14 16:41pm    
Thank you, Sergey ;)
You need two separate functions: the one you have and one that converts numbers to the sequence of digit words: NumberToDigitWords(23) => "two three"
Then in the main NumberToWords, call the NumberToDigitWords in the places where you want that behavior, instead of simply calling NumberToWords recursively.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900