views:

797

answers:

2

Is there a library or a class/function that I can use to convert an integer to it's verbal representation?

Example input: 4,567,788

Example output: Four million, Five hundred sixty-seven thousand, seven hundred eighty-eight

For reference, I am using C# and .NET 3.5.

+10  A: 

Something like this or this should get you started.

Keep in mind that some cultures have a different definition of "billion"

Chris Ballance
the first example works, minus a few bugs. It likes to say things like 'Fifty Zero'
Malfist
Regarding the second, I believe in some cultures a billion is actually a million millions, versus the thousand millions many expect.
ccook
http://www.guardian.co.uk/notesandqueries/query/0,5753,-61424,00.html
ccook
ccook - you are correct. Some cultures, including old English consider a thousand million to be a millard and a million million to be a billion. It is fairly simply to change my example code to obtain this output instead though.
BlackWasp
+7  A: 

There was a code golf here on SO that addressed this:

http://stackoverflow.com/questions/309884/code-golf-number-to-words

May be of some help.

"May be of some help" is a nice way of saying "duplicate question", right? Because there's at least one C# solution in there.
bzlm
@bzlm: Very good point. Question has been edited. Hopefully closed soon.
Geoffrey Chetwood
I don't really see a code golf and this specific platform questions as being exact duplicates. Also, code golfs sometimes tend to value the shortest (and possibly obscure) method.
Simucal
I agree; code golf is all well and good when you know what you're doing, and you're trying to express some algorithm as succinctly as possible, but perhaps for someone just starting out with a technique, slightly more verbose (though not unnecessarily so) code is more helpful.
Rob