Convert number to word

I have a big number like: 123 456 789. Now I'll to writ it like this

123 million 456 thousand 789

I've search on the internet but nothing found that works.

How can you do that? Thanks.

• – Dr. belisarius Feb 10 '15 at 17:32
• To the close voters: the questions are similar but the desired output is different, permitting different approaches. I will not overrule a Close but please consider this. – Mr.Wizard Feb 11 '15 at 20:56

3 Answers

Mathematica 10 introduces IntegerName:

• IntegerName[n] gives a string containing the full English name of the integer n.

• IntegerName[n,"type"] gives a string of the specified type.

Possible types include:

• "DigitsWords" a combination of three-digit numbers and words
• "Words" using only words
• "Approximate" the first few digits plus thousands, millions, etc.
• "ApproximateWords" the first few digits as words plus thousands, etc.

Example:

IntegerName[123456789]

"123 million 456 thousand 789"


ybeltukov comments that small numbers are converted to words:

IntegerName[84]

"eighty‐four"


If this is a problem one could use:

fn = If[Abs[#] < 1000, IntegerString, IntegerName][#] &;

fn /@ {51, 781, 25483}

{"51", "781", "25 thousand 483"}

• Hah this is great I love it. Should make an expression-to-English translator. "E to the i theta tensor product etc..." – SubSevn Feb 10 '15 at 18:50
• It exists in audio: Speak[Exp[I \[Theta]]] or Speak[BarChart[{3, 4, 5}]] and turn up your speakers. – David G. Stork Feb 10 '15 at 19:42
• And in text: SpokenString[Exp[I \[Theta]]] or SpokenString[BarChart[{3,4,5}]]. – David G. Stork Feb 10 '15 at 19:57
• @DavidG.Stork This is magic. – SubSevn Feb 11 '15 at 11:56
• Do you know how to deal with shot numbers? IntegerName[123, "DigitsWords"] returns one hundred twenty-three. I'm not sure that it's desired output. – ybeltukov Feb 11 '15 at 23:55

You people with your fancy version 10 have it too easy.

 StringJoin@Reverse@MapIndexed[ToString[#] <>
{"", " thousand ", " million ", " billion ", " trillion" }[[First@#2]] &,
Reverse@(FromDigits /@
Partition[PadLeft[#, 3 - Mod[#, 3, 1] + # &@Length@#] , 3])] &@
IntegerDigits[123456789]


"123 million 456 thousand 789"

• As a long-time version 7 user I always like seeing backward-compatible answers. +1 – Mr.Wizard Feb 10 '15 at 18:57

In version 9 and earlier you can do it with Riffle and IntegerDigits[...,1000]:

name[n_Integer] := If[n < 0, "minus ", ""] <> Riffle[ToString /@ IntegerDigits[n, 1000],
{" thousand ", " million ", " billion ", " trillion "}, {-2, 2, -2}]

{#, name@#} & /@ ((-12)^Range@10) // TableForm


• Great! It would be even better if this handled negative numbers. – Mr.Wizard Feb 12 '15 at 7:03
• @Mr.Wizard I just added a prefix depending on the sign – ybeltukov Feb 12 '15 at 11:52
• nice, i knew there was a better way than what i cooked up. – george2079 Feb 12 '15 at 12:23
• I notice you chose "minus" whereas IntegerName uses "negative" -- is the latter an American English thing? p.s. I think it would be arguably better to put the ToString /@ inside Riffle. – Mr.Wizard Feb 12 '15 at 12:23
• May be. My knowledge of English is not enough. There are some discussions: Math.SE, MO.SE. Of course, ToString of String looks strange :-) – ybeltukov Feb 12 '15 at 12:38