Here are some RINO (Random In Name Only) numbers:
| -965,660,807,024,687,488 | = negative nine hundred and sixty-five quadrillion six hundred and sixty trillion eight hundred and seven billion twenty-four million six hundred and eighty-seven thousand four hundred and eighty-eight |
| 0 | = zero |
| 6 | = six |
| 70 | = seventy |
| 365 | = three hundred and sixty-five |
| 2,364 | = two thousand three hundred and sixty-four |
| 80,237 | = eighty thousand two hundred and thirty-seven |
| 757,028 | = seven hundred and fifty-seven thousand twenty-eight |
| 8,041,851 | = eight million forty-one thousand eight hundred and fifty-one |
| 78,795,296 | = seventy-eight million seven hundred and ninety-five thousand two hundred and ninety-six |
| 240,369,211 | = two hundred and forty million three hundred and sixty-nine thousand two hundred and eleven |
| 8,959,850,072 | = eight billion nine hundred and fifty-nine million eight hundred and fifty thousand seventy-two |
| 78,590,925,862 | = seventy-eight billion five hundred and ninety million nine hundred and twenty-five thousand eight hundred and sixty-two |
| 987,718,415,958 | = nine hundred and eighty-seven billion seven hundred and eighteen million four hundred and fifteen thousand nine hundred and fifty-eight |
| 3,502,555,216,662 | = three trillion five hundred and two billion five hundred and fifty-five million two hundred and sixteen thousand six hundred and sixty-two |
| 95,823,589,130,304 | = ninety-five trillion eight hundred and twenty-three billion five hundred and eighty-nine million one hundred and thirty thousand three hundred and four |
| 422,257,649,060,338 | = four hundred and twenty-two trillion two hundred and fifty-seven billion six hundred and forty-nine million sixty thousand three hundred and thirty-eight |
| 5,792,418,684,810,401 | = five quadrillion seven hundred and ninety-two trillion four hundred and eighteen billion six hundred and eighty-four million eight hundred and ten thousand four hundred and one |
| 44,846,875,881,776,208 | = forty-four quadrillion eight hundred and forty-six trillion eight hundred and seventy-five billion eight hundred and eighty-one million seven hundred and seventy-six thousand two hundred and eight |
| 875,049,875,583,499,648 | = eight hundred and seventy-five quadrillion forty-nine trillion eight hundred and seventy-five billion five hundred and eighty-three million four hundred and ninety-nine thousand six hundred and forty-eight |
The output above was produced with:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Translate Digits to Words</title>
</head>
<body>
<h1>Numbers Converted Into Words</h1>
<p>Here are some RINO (Random In Name Only) numbers:</p>
<?php
// Example usage:
// http://en.wikipedia.org/wiki/Names_of_large_numbers
echo "<!-- Tables are for tabular data -->";
echo "<table>";
$maximum_size = pow(10,18);
$number = mt_rand($maximum_size/10, $maximum_size - 1);
// careful with the formatting of large numbers, errors are introduced in the result if default formatting is preserved
echo "<tr><td>-" . number_format($number, 0, ".", ",") . "</td><td> = <strong>" . translateToWords(intval(number_format(-1*$number, 0, "", ""))) . "</strong></td></tr>";
echo "<tr><td>" . number_format(0, 0, ".", ",") . "</td><td> = <strong>" . translateToWords(0) . "</strong></td></tr>";
for ($max = pow(10,1); $max <= $maximum_size; $max *= pow(10,1))
{
$number = mt_rand($max / 10, $max - 1);
echo "<tr><td>" . number_format($number, 0, ".", ",") . "</td><td> = <strong>" . translateToWords(intval(number_format($number, 0, "", ""))) . "</strong></td></tr>";
}
echo "</table>";
function translateToWords($number)
{
/*****
* A recursive function to turn digits into words
* Numbers must be integers from -999,999,999,999 to 999,999,999,999 inclussive.
*
* (C) 2010 Peter Ajtai
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* See the GNU General Public License: <http://www.gnu.org/licenses/>.
*
*/
// zero is a special case, it cause problems even with typecasting if we don't deal with it here
$max_size = pow(10,18);
if (!$number) return "zero";
if (is_int($number) && $number < abs($max_size))
{
switch ($number)
{
// set up some rules for converting digits to words
case $number < 0:
$prefix = "negative";
$suffix = translateToWords(-1*$number);
$string = $prefix . " " . $suffix;
break;
case 1:
$string = "one";
break;
case 2:
$string = "two";
break;
case 3:
$string = "three";
break;
case 4:
$string = "four";
break;
case 5:
$string = "five";
break;
case 6:
$string = "six";
break;
case 7:
$string = "seven";
break;
case 8:
$string = "eight";
break;
case 9:
$string = "nine";
break;
case 10:
$string = "ten";
break;
case 11:
$string = "eleven";
break;
case 12:
$string = "twelve";
break;
case 13:
$string = "thirteen";
break;
// fourteen handled later
case 15:
$string = "fifteen";
break;
case $number < 20:
$string = translateToWords($number%10);
// eighteen only has one "t"
if ($number == 18)
{
$suffix = "een";
} else
{
$suffix = "teen";
}
$string .= $suffix;
break;
case 20:
$string = "twenty";
break;
case 30:
$string = "thirty";
break;
case 40:
$string = "forty";
break;
case 50:
$string = "fifty";
break;
case 60:
$string = "sixty";
break;
case 70:
$string = "seventy";
break;
case 80:
$string = "eighty";
break;
case 90:
$string = "ninety";
break;
case $number < 100:
$prefix = translateToWords($number-$number%10);
$suffix = translateToWords($number%10);
$string = $prefix . "-" . $suffix;
break;
// handles all number 100 to 999
case $number < pow(10,3):
// floor return a float not an integer
$prefix = translateToWords(intval(floor($number/pow(10,2)))) . " hundred";
if ($number%pow(10,2)) $suffix = " and " . translateToWords($number%pow(10,2));
$string = $prefix . $suffix;
break;
case $number < pow(10,6):
// floor return a float not an integer
$prefix = translateToWords(intval(floor($number/pow(10,3)))) . " thousand";
if ($number%pow(10,3)) $suffix = translateToWords($number%pow(10,3));
$string = $prefix . " " . $suffix;
break;
case $number < pow(10,9):
// floor return a float not an integer
$prefix = translateToWords(intval(floor($number/pow(10,6)))) . " million";
if ($number%pow(10,6)) $suffix = translateToWords($number%pow(10,6));
$string = $prefix . " " . $suffix;
break;
case $number < pow(10,12):
// floor return a float not an integer
$prefix = translateToWords(intval(floor($number/pow(10,9)))) . " billion";
if ($number%pow(10,9)) $suffix = translateToWords($number%pow(10,9));
$string = $prefix . " " . $suffix;
break;
case $number < pow(10,15):
// floor return a float not an integer
$prefix = translateToWords(intval(floor($number/pow(10,12)))) . " trillion";
if ($number%pow(10,12)) $suffix = translateToWords($number%pow(10,12));
$string = $prefix . " " . $suffix;
break;
// Be careful not to pass default formatted numbers in the quadrillions+ into this function
// Default formatting is float and causes errors
case $number < pow(10,18):
// floor return a float not an integer
$prefix = translateToWords(intval(floor($number/pow(10,15)))) . " quadrillion";
if ($number%pow(10,15)) $suffix = translateToWords($number%pow(10,15));
$string = $prefix . " " . $suffix;
break;
}
} else
{
echo "ERROR with - $number<br/> Number must be an integer between -" . number_format($max_size, 0, ".", ",") . " and " . number_format($max_size, 0, ".", ",") . " exclussive.";
}
return $string;
}
?>
<p>The output above was produced with:</p>
<?php
highlight_file(__FILE__);
?>
</body>
</html>