Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's one in PHP, from <em><a href="http://www.phpro.org/examples/Convert-Numbers-to-Words.html" rel="nofollow noreferrer">Convert Numbers to Words</a></em>:</p> <pre><code>convert_number(2850) </code></pre> <p>returns</p> <blockquote> <p>Two Thousand Eight Hundred and Fifty</p> </blockquote> <p>and if you want an even more awesome one that handles commas and numbers up to vigintillion check out zac hesters work at <em><a href="http://code.zacharyhester.com/?type=flat&amp;lang=php&amp;name=language" rel="nofollow noreferrer">Language Display Functions</a></em>:</p> <pre><code>function convert_number($number) { if (($number &lt; 0) || ($number &gt; 999999999)) { throw new Exception("Number is out of range"); } $Gn = floor($number / 1000000); /* Millions (giga) */ $number -= $Gn * 1000000; $kn = floor($number / 1000); /* Thousands (kilo) */ $number -= $kn * 1000; $Hn = floor($number / 100); /* Hundreds (hecto) */ $number -= $Hn * 100; $Dn = floor($number / 10); /* Tens (deca) */ $n = $number % 10; /* Ones */ $res = ""; if ($Gn) { $res .= convert_number($Gn) . " Million"; } if ($kn) { $res .= (empty($res) ? "" : " ") . convert_number($kn) . " Thousand"; } if ($Hn) { $res .= (empty($res) ? "" : " ") . convert_number($Hn) . " Hundred"; } $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", "Nineteen"); $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eigthy", "Ninety"); if ($Dn || $n) { if (!empty($res)) { $res .= " and "; } if ($Dn &lt; 2) { $res .= $ones[$Dn * 10 + $n]; } else { $res .= $tens[$Dn]; if ($n) { $res .= "-" . $ones[$n]; } } } if (empty($res)) { $res = "zero"; } return $res; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload