Skip to content

Instantly share code, notes, and snippets.

@Alanaktion
Last active December 21, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alanaktion/6265002 to your computer and use it in GitHub Desktop.
Save Alanaktion/6265002 to your computer and use it in GitHub Desktop.
PHP function to return massive numbers as readable strings such as "63.2 quadrillion" instead of 63200000000000000. This function uses short scale number formats, the standard in the U.S.
<?php
function bigformat($n) {
// Start with a Googol and work down
if($n>pow(10,100))
return round(($n/pow(10,100)),1).' googol';
// I'll add more later
if($n>pow(1000,32))
return round(($n/pow(1000,32)),1).' untrigintillion';
if($n>pow(1000,31))
return round(($n/pow(1000,31)),1).' trigintillion';
if($n>pow(1000,30))
return round(($n/pow(1000,30)),1).' novemvigintillion';
if($n>pow(1000,29))
return round(($n/pow(1000,29)),1).' octovigintillion';
if($n>pow(1000,28))
return round(($n/pow(1000,28)),1).' septenvigintillion';
if($n>pow(1000,27))
return round(($n/pow(1000,27)),1).' sexvigintillion';
if($n>pow(1000,26))
return round(($n/pow(1000,26)),1).' quinvigintillion';
if($n>pow(1000,25))
return round(($n/pow(1000,25)),1).' quattuorvigintillion';
if($n>pow(1000,24))
return round(($n/pow(1000,24)),1).' trevigintillion';
if($n>pow(1000,23))
return round(($n/pow(1000,23)),1).' duovigintillion';
if($n>pow(1000,22))
return round(($n/pow(1000,22)),1).' unvigintillion';
if($n>pow(1000,21))
return round(($n/pow(1000,21)),1).' vigintillion';
if($n>pow(1000,20))
return round(($n/pow(1000,20)),1).' novemdecillion';
if($n>pow(1000,19))
return round(($n/pow(1000,19)),1).' octodecillion';
if($n>pow(1000,18))
return round(($n/pow(1000,18)),1).' septendecillion';
if($n>pow(1000,17))
return round(($n/pow(1000,17)),1).' sexdecillion';
if($n>pow(1000,16))
return round(($n/pow(1000,16)),1).' quindecillion';
if($n>pow(1000,15))
return round(($n/pow(1000,15)),1).' quattuordecillion';
if($n>pow(1000,14))
return round(($n/pow(1000,14)),1).' tredecillion';
if($n>pow(1000,13))
return round(($n/pow(1000,13)),1).' duodecillion';
if($n>pow(1000,12))
return round(($n/pow(1000,12)),1).' undecillion';
if($n>pow(1000,11))
return round(($n/pow(1000,11)),1).' decillion';
if($n>pow(1000,10))
return round(($n/pow(1000,10)),1).' nonillion';
if($n>pow(1000,9))
return round(($n/pow(1000,9)),1).' octillion';
if($n>pow(1000,8))
return round(($n/pow(1000,8)),1).' septillion';
if($n>pow(1000,7))
return round(($n/pow(1000,7)),1).' sextillion';
if($n>pow(1000,6))
return round(($n/pow(1000,6)),1).' quintillion';
if($n>pow(1000,5))
return round(($n/pow(1000,5)),1).' quadrillion';
if($n>pow(1000,4))
return round(($n/pow(1000,4)),1).' trillion';
if($n>pow(1000,3))
return round(($n/pow(1000,3)),1).' billion';
if($n>1000000)
return round(($n/1000000),1).' million';
if($n>1000)
return round(($n/1000),1).' thousand';
return number_format($n);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment