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.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI 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.
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"}
Speak[Exp[I \[Theta]]]
or Speak[BarChart[{3, 4, 5}]]
and turn up your speakers.
$\endgroup$
Feb 10, 2015 at 19:42
SpokenString[Exp[I \[Theta]]]
or SpokenString[BarChart[{3,4,5}]]
.
$\endgroup$
Feb 10, 2015 at 19:57
IntegerName[123, "DigitsWords"]
returns one hundred twenty-three
. I'm not sure that it's desired output.
$\endgroup$
Feb 11, 2015 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"
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
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
.
$\endgroup$
Feb 12, 2015 at 12:23