2DaysAway Posted August 1, 2008 Share Posted August 1, 2008 Instead of showing a number, say, 3,750,000,000 I would like it to display 3.75B Javascript may work better for something like this, any help would be great, thank you Link to comment https://forums.phpfreaks.com/topic/117763-solved-shorten-up-large-number-displays/ Share on other sites More sharing options...
.josh Posted August 1, 2008 Share Posted August 1, 2008 http://www.php.net/sprintf Link to comment https://forums.phpfreaks.com/topic/117763-solved-shorten-up-large-number-displays/#findComment-605713 Share on other sites More sharing options...
Daniel0 Posted August 1, 2008 Share Posted August 1, 2008 Crayon Violent, sprintf() doesn't make that possible. You'll have to write your own function. Here is a small one I wrote for this purpose: <?php function format($number) { $suffix = array('', 'K', 'M', 'B'); for($i = 0, $max = sizeof($suffix)-1; $i < $max; $i++) { $pos = strpos($number, '.'); if ($pos !== false) { $length = strlen(substr($number, 0, $pos)); } else { $length = strlen($number); } if ($length < 3) { break; } $number = round($number / 1000, 2); } return $number . $suffix[$i]; } echo format(3750000000); // output: 3.75B ?> Link to comment https://forums.phpfreaks.com/topic/117763-solved-shorten-up-large-number-displays/#findComment-605721 Share on other sites More sharing options...
.josh Posted August 1, 2008 Share Posted August 1, 2008 for some unknown reason I thought he meant scientific notation. Link to comment https://forums.phpfreaks.com/topic/117763-solved-shorten-up-large-number-displays/#findComment-605734 Share on other sites More sharing options...
2DaysAway Posted August 2, 2008 Author Share Posted August 2, 2008 thanks alot guys, I will go with that. Link to comment https://forums.phpfreaks.com/topic/117763-solved-shorten-up-large-number-displays/#findComment-605805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.