11,481,850 members (63,311 online)

# Converting numbers to the word equivalent.

, 12 May 2013 CPOL 41.7K 13
 Rate this:
If your tutor asks you to convert numbers to words (i.e. 565 to a string "Five hundred and sixty-five") then you are not alone! Here is the simplest, most foolproof way to do it.
If your tutor asks you to convert numbers to words (i.e. 565 to a string "Five hundred and sixty-five") then you are not alone! This question gets asked here very frequently, so here is the simple, foolproof way to solve your problem. It shows the outline of how to do it, and it is then up to you to fill in the detail, comments etc. - otherwise every-bodies would look the same, and you might get caught for copying!
```        public static string ConvertToWords(int number)
{
switch (number)
{
case 0:
return "Zero";
case 1:
return "One";
...
case 568:
return "Five hundred and sixty-eight";
case 569:
return "Five hundred and sixty-nine";
}
throw new ArgumentOutOfRangeException("Number greater than infinity!");
}
```

I cannot remember who originally posted this coding gem, and I can't find it with a quick search, but if you know who did post it let me know and I will provide full credit.

The original version of this software was written by Smithers-Jones[^] in C++ and is available here[^] My thanks for the inspiration and the excellent work!

I am indebted to Luc Pattyn for pointing out the error in versions before V3.0 regarding the placement of a hyphen between the tens and unit digits. He correctly pointed out here[^] that numbers should not be written as "twenty one" but as "twenty-one".

V2.0: Credit for original version added - OriginalGriff[/edit]
V3.0: Corrected the hyphenation between the tens digit and the units digit - OriginalGriff[/edit]
V4.0: Link to the message of Luc Pattyn corrected - ProgramFOX[/edit]

## Share

CEO
Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

 Good attempt but you'll have to write it for every number. t... Javedsamrt29-Nov-11 22:35 Javedsamrt 29-Nov-11 22:35
 Re: Good attempt but you'll have to write it for every number. t... DidiKunz13-May-13 0:20 DidiKunz 13-May-13 0:20
 Reason for my vote of 5 Yep, that solution efficiently gets ... Doc Lobster6-Nov-11 23:00 Doc Lobster 6-Nov-11 23:00
 is this some kind of joke??? danny3339-Oct-11 5:47 danny333 9-Oct-11 5:47
 Reason for my vote of 1 very bad solution u need to write ea... bashar Haydar6-Oct-10 21:35 bashar Haydar 6-Oct-10 21:35
 Whoosh! That or perhaps some people want it to work for numb... Edbert P19-Aug-10 21:13 Edbert P 19-Aug-10 21:13
 Reason for my vote of 1 Voted 1 because it's not a good tip.... Simon Dufour19-Aug-10 12:38 Simon Dufour 19-Aug-10 12:38
 "hey griff, you are maybe thinking about this" That's the one! I have credited you in the tip. Funny: I had a vague idea it was JSOP, didn't think of you at all - sorry! :blush:
 Reason for my vote of 5 By the way, what if I need to handle... emartinho19-Aug-10 6:18 emartinho 19-Aug-10 6:18
 Reason for my vote of 5 Finally! But can you help me with th... Yayozama19-Aug-10 5:11 Yayozama 19-Aug-10 5:11
 Really awesome HimanshuJoshi19-Aug-10 4:46 HimanshuJoshi 19-Aug-10 4:46
 Reason for my vote of 5 sir, i copied your code now my teach... Yusuf19-Aug-10 4:27 Yusuf 19-Aug-10 4:27
 Reason for my vote of 5 Lovely! And the first post which has... Ankur\m/19-Aug-10 4:24 Ankur\m/ 19-Aug-10 4:24
 Doesn't everyone do it like this? :) Mike Hankey19-Aug-10 4:19 Mike Hankey 19-Aug-10 4:19
 You misspelled sixty-eight and sixty-nine and forgot to use ... Ennis Ray Lynch, Jr.19-Aug-10 4:16 Ennis Ray Lynch, Jr. 19-Aug-10 4:16
 You can improve it a bit though - forgot about negative numb... Svetlin Panayotov19-Aug-10 4:15 Svetlin Panayotov 19-Aug-10 4:15
 Reason for my vote of 5 So brilliant and simple! There's eve... Svetlin Panayotov19-Aug-10 4:13 Svetlin Panayotov 19-Aug-10 4:13
 I'd like to see some unit tests, your method seems a bit err... Luc Pattyn19-Aug-10 3:54 Luc Pattyn 19-Aug-10 3:54
 Reason for my vote of 5 Good one! :D Nuri Ismail19-Aug-10 3:47 Nuri Ismail 19-Aug-10 3:47
 Reason for my vote of 5 Lost for words. Can you translate th... digital man19-Aug-10 3:42 digital man 19-Aug-10 3:42
 Reason for my vote of 5 Excellent! hammerstein0519-Aug-10 3:35 hammerstein05 19-Aug-10 3:35
 Reason for my vote of 5 Fantastic! :) Alison P19-Aug-10 3:20 Alison P 19-Aug-10 3:20
 Reason for my vote of 5 Funny linuxjr19-Aug-10 3:18 linuxjr 19-Aug-10 3:18
 Reason for my vote of 5 Good one!!! Johnny J.19-Aug-10 3:09 Johnny J. 19-Aug-10 3:09
 Last Visit: 31-Dec-99 19:00     Last Update: 24-May-15 10:28 Refresh « Prev123 Next »