12,953,479 members (52,151 online)
alternative version

#### Stats

67.5K views
14 bookmarked
Posted 19 Aug 2010

# Converting numbers to the word equivalent.

, 12 May 2013 CPOL
 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?

## You may also be interested in...

 Pro

 First PrevNext
 Be serious :-) rwtrecasd14-May-13 6:11 rwtrecasd 14-May-13 6:11
 My vote of 5 TnTinMn13-May-13 16:42 TnTinMn 13-May-13 16:42
 It reminds me... BarrRobot13-May-13 14:05 BarrRobot 13-May-13 14:05
 My vote of 5! Matt T Heffron13-May-13 11:49 Matt T Heffron 13-May-13 11:49
 You gotta be kidding... You voted this 5 stars? marsman_CA13-May-13 8:46 marsman_CA 13-May-13 8:46
 Re: You gotta be kidding... You voted this 5 stars? marsman_CA13-May-13 8:49 marsman_CA 13-May-13 8:49
 Re: You gotta be kidding... You voted this 5 stars? Ravi Bhavnani13-May-13 9:10 Ravi Bhavnani 13-May-13 9:10
 Re: You gotta be kidding... You voted this 5 stars? OriginalGriff13-May-13 9:35 OriginalGriff 13-May-13 9:35
 Re: You gotta be kidding... You voted this 5 stars? OriginalGriff13-May-13 9:36 OriginalGriff 13-May-13 9:36
 An optimised answer Juan Falgueras Cano13-May-13 8:24 Juan Falgueras Cano 13-May-13 8:24
 My vote of 4 Juan Falgueras Cano13-May-13 8:22 Juan Falgueras Cano 13-May-13 8:22
 Nice, but... Ravi Bhavnani13-May-13 5:19 Ravi Bhavnani 13-May-13 5:19
 Funny! DidiKunz12-May-13 23:23 DidiKunz 12-May-13 23:23
 my vote of 5 Simon_Whale12-May-13 22:35 Simon_Whale 12-May-13 22:35
 Re: my vote of 5 OriginalGriff12-May-13 22:47 OriginalGriff 12-May-13 22:47
 My vote of 4 Marco Bertschi12-May-13 9:37 Marco Bertschi 12-May-13 9:37
 Re: My vote of 4 OriginalGriff12-May-13 21:31 OriginalGriff 12-May-13 21:31
 My vote of 1 Stephen Hardie12-May-13 8:19 Stephen Hardie 12-May-13 8:19
 Re: My vote of 1 Marco Bertschi12-May-13 9:34 Marco Bertschi 12-May-13 9:34
 My vote of 5 + There is a shorter way ProgramFOX12-May-13 6:57 ProgramFOX 12-May-13 6:57
 My vote of 5 JackDingler14-Jan-13 7:15 JackDingler 14-Jan-13 7:15
 This a great example of how to do a home work assignment, for people who don't really want to learn programming. It satisfied the conditions of the homework assignment. It doesn't require that the student be bothered with actually learning programming. It still requires that the student do something to complete the assignment. We need more example like this, for folks who want the pros to do all their homework assignments for them.
 Re: My vote of 5 Marco Bertschi12-May-13 9:35 Marco Bertschi 12-May-13 9:35