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); Link to comment https://forums.phpfreaks.com/topic/126656-solved-numformat/ 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); ?> Link to comment https://forums.phpfreaks.com/topic/126656-solved-numformat/#findComment-655001 Share on other sites More sharing options...
2DaysAway Posted October 1, 2008 Author Share Posted October 1, 2008 seems to work, thank you Link to comment https://forums.phpfreaks.com/topic/126656-solved-numformat/#findComment-655012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.