Warptweet Posted April 15, 2007 Share Posted April 15, 2007 Here is my code to display the rating of a game... DAtabase connection stuff ehre... blah blah blah echo "" . $row['upload_rating'] . ""; end the database stuff here... blah blah blah But, sometimes the rating can be like 9.372783617863768541 How can I make it so that is the rating is like 9.15243 it only shows 9.152 (AKA, only display the first four integers?) Link to comment https://forums.phpfreaks.com/topic/47058-display-maximum-4-digits/ Share on other sites More sharing options...
AndyB Posted April 15, 2007 Share Posted April 15, 2007 http://ca.php.net/manual/en/function.round.php Link to comment https://forums.phpfreaks.com/topic/47058-display-maximum-4-digits/#findComment-229520 Share on other sites More sharing options...
pocobueno1388 Posted April 15, 2007 Share Posted April 15, 2007 $rating = substr('$row[upload_rating]', 6); Link to comment https://forums.phpfreaks.com/topic/47058-display-maximum-4-digits/#findComment-229521 Share on other sites More sharing options...
kenrbnsn Posted April 15, 2007 Share Posted April 15, 2007 You want to use either sprintf() or printf() <?php $x = 9.152437895656675; printf("%01.3f",$x); ?> Ken Link to comment https://forums.phpfreaks.com/topic/47058-display-maximum-4-digits/#findComment-229555 Share on other sites More sharing options...
AndyB Posted April 15, 2007 Share Posted April 15, 2007 Round() really can do it: float round ( float $val [, int $precision] ) Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default). Link to comment https://forums.phpfreaks.com/topic/47058-display-maximum-4-digits/#findComment-229628 Share on other sites More sharing options...
ted_chou12 Posted April 15, 2007 Share Posted April 15, 2007 If you are talking about calculations here, use round(), if talking about text, use substr(). Ted Link to comment https://forums.phpfreaks.com/topic/47058-display-maximum-4-digits/#findComment-229663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.