2DaysAway Posted October 1, 2008 Share Posted October 1, 2008 I need this function to figure up to quadrillion. I know that isn't even right for trillion. I'm sure it's something silly and small but I'm having a brainfart, any help please? function hformat($number) { $suffix = array('', ' K', ' M', ' B',' T'); for($i = 0, $max = sizeof($suffix)-2; $i < $max; $i++) { $pos = strpos($number, '.'); if ($pos !== false) { $length = strlen(substr($number, 0, $pos)); } else { $length = strlen($number); } if ($length < 4) { break; } $number = round($number / 1000, 2); } return $number . $suffix[$i]; } echo hformat($hint); Quote Link to comment Share on other sites More sharing options...
sasa Posted October 1, 2008 Share Posted October 1, 2008 try <?php function hformat($number) { $suffix = array('', ' K', ' M', ' B',' T', ' Q'); $max = count($suffix) - 1; while ($number >= 1000 and $i < $max){ $number /= 1000; $i++; } $number = round($number, 2); return $number . $suffix[$i]; } echo hformat(1234567891234567); ?> Quote Link to comment Share on other sites More sharing options...
2DaysAway Posted October 1, 2008 Author Share Posted October 1, 2008 seems to work, thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.