Click here to Skip to main content
Full site     10M members (37.4K online)    

Converting numbers to the word equivalent.

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".
 
[edit]V2.0: Credit for original version added - OriginalGriff[/edit]
[edit]V3.0: Corrected the hyphenation between the tens digit and the units digit - OriginalGriff[/edit]
[edit]V4.0: Link to the message of Luc Pattyn corrected - ProgramFOX[/edit]
 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search 
Per page   
GeneralMy vote of 5
TnTinMn
4hrs 39mins ago 
QuestionIt reminds me...
BarrRobot
7hrs 16mins ago 
GeneralMy vote of 5!
Matt T Heffron
9hrs 32mins ago 
QuestionYou gotta be kidding... You voted this 5 stars?
marsman_CA
12hrs 35mins ago 
AnswerRe: You gotta be kidding... You voted this 5 stars?
marsman_CA
12hrs 32mins ago 
GeneralRe: You gotta be kidding... You voted this 5 stars?
Ravi Bhavnani
12hrs 11mins ago 
GeneralRe: You gotta be kidding... You voted this 5 stars?
OriginalGriff
11hrs 46mins ago 
GeneralRe: You gotta be kidding... You voted this 5 stars?
OriginalGriff
11hrs 45mins ago 
QuestionAn optimised answer
Juan Falgueras Cano
12hrs 57mins ago 
GeneralMy vote of 4
Juan Falgueras Cano
12hrs 59mins ago 
SuggestionNice, but...
Ravi Bhavnani
16hrs 2mins ago 
QuestionFunny!
DidiKunz
21hrs 58mins ago 
Questionmy vote of 5
Simon_Whale
22hrs 46mins ago 
AnswerRe: my vote of 5
OriginalGriff
22hrs 34mins ago 
GeneralMy vote of 4
Marco Bertschi
12 May '13 - 9:37 
GeneralRe: My vote of 4
OriginalGriff
23hrs 50mins ago 
GeneralMy vote of 1
Stephen Hardie
12 May '13 - 8:19 
GeneralRe: My vote of 1
Marco Bertschi
12 May '13 - 9:34 
GeneralMy vote of 5 + There is a shorter way
ProgramFOX
12 May '13 - 6:57 
QuestionMy vote of 5
JackDingler
14 Jan '13 - 7:15 
AnswerRe: My vote of 5
Marco Bertschi
12 May '13 - 9:35 
GeneralMy vote of 5
SoMad
10 Jul '12 - 17:01 
GeneralRe: My vote of 5
OriginalGriff
10 Jul '12 - 21:50 
GeneralRe: My vote of 5
SoMad
10 Jul '12 - 22:02 
GeneralGood attempt but you'll have to write it for every number. t...
Javedsamrt
29 Nov '11 - 21:35 
GeneralRe: Good attempt but you'll have to write it for every number. t...
DidiKunz
22hrs 1 min ago 
GeneralReason for my vote of 5 Yep, that solution efficiently gets ...
Doc Lobster
6 Nov '11 - 22:00 
Generalis this some kind of joke???
danny333
9 Oct '11 - 4:47 
GeneralReason for my vote of 1 very bad solution u need to write ea...
bashar Haydar
6 Oct '10 - 20:35 
GeneralWhoosh! That or perhaps some people want it to work for numb...
Edbert P
19 Aug '10 - 20:13 
GeneralReason for my vote of 1 Voted 1 because it's not a good tip....
Simon Dufour
19 Aug '10 - 11:38 
General"hey griff, you are maybe thinking about this" That's the on...
OriginalGriff
19 Aug '10 - 6:32 
Generalhey griff, you are maybe thinking about this (http://www.cod...
Smithers-Jones
19 Aug '10 - 5:32 
GeneralReason for my vote of 5 By the way, what if I need to handle...
emartinho
19 Aug '10 - 5:18 
GeneralReason for my vote of 5 Finally! But can you help me with th...
Yayozama
19 Aug '10 - 4:11 
GeneralReally awesome
HimanshuJoshi
19 Aug '10 - 3:46 
GeneralReason for my vote of 5 sir, i copied your code now my teach...
Yusuf
19 Aug '10 - 3:27 
GeneralReason for my vote of 5 Lovely! And the first post which has...
Ankur\m/
19 Aug '10 - 3:24 
GeneralDoesn't everyone do it like this? :)
Mike Hankey
19 Aug '10 - 3:19 
GeneralYou misspelled sixty-eight and sixty-nine and forgot to use ...
Ennis Ray Lynch, Jr.
19 Aug '10 - 3:16 
GeneralYou can improve it a bit though - forgot about negative numb...
Svetlin Panayotov
19 Aug '10 - 3:15 
GeneralReason for my vote of 5 So brilliant and simple! There's eve...
Svetlin Panayotov
19 Aug '10 - 3:13 
GeneralI'd like to see some unit tests, your method seems a bit err...
Luc Pattyn
19 Aug '10 - 2:54 
GeneralReason for my vote of 5 Good one! :D
Nuri Ismail
19 Aug '10 - 2:47 
GeneralReason for my vote of 5 Lost for words. Can you translate th...
digital man
19 Aug '10 - 2:42 
GeneralReason for my vote of 5 Excellent!
hammerstein05
19 Aug '10 - 2:35 
GeneralReason for my vote of 5 Fantastic! :)
Alison P
19 Aug '10 - 2:20 
GeneralReason for my vote of 5 Funny
linuxjr
19 Aug '10 - 2:18 
GeneralReason for my vote of 5 Good one!!!
Johnny J.
19 Aug '10 - 2:09 
GeneralReason for my vote of 5 Does it work just for the English la...
CPallini
19 Aug '10 - 2:04 

Last Updated 12 May 2013 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2013