Jay2391 Posted October 5, 2007 Share Posted October 5, 2007 Example: I have a greater total of 61 and I score 45 $i= 61; $y= 45; $pct = ($i /$y) * 100; one is tha correct ??? Two how can i limit the number that result diplays (0.987654321 - i just want .987) and how do i turn off this error message??? Warning: Division by zero in localhost\info.php on line xxx Link to comment https://forums.phpfreaks.com/topic/71900-calculation-and-limiting-decimals/ Share on other sites More sharing options...
marcus Posted October 5, 2007 Share Posted October 5, 2007 <?php $i = 61; $y = 45; $pct = ($i/$y) * 100; echo "Before round: " . $pct . "<br />\n"; echo "After round: " . round($pct,3); ?> Before round: 135.555555556 After round: 135.556 Link to comment https://forums.phpfreaks.com/topic/71900-calculation-and-limiting-decimals/#findComment-362202 Share on other sites More sharing options...
atyndall Posted October 5, 2007 Share Posted October 5, 2007 And to remove any error messages you may encounter put: <?php ini_set('display_errors', False); //code... ?> (on the first line after your <?php tag) Link to comment https://forums.phpfreaks.com/topic/71900-calculation-and-limiting-decimals/#findComment-362203 Share on other sites More sharing options...
Jay2391 Posted October 8, 2007 Author Share Posted October 8, 2007 Thanks for everything .... is all good, i have one ,more ??? the total of $pct is Example: 0.123 how can i eliminate the 0 and just display .123 Link to comment https://forums.phpfreaks.com/topic/71900-calculation-and-limiting-decimals/#findComment-364233 Share on other sites More sharing options...
MasterACE14 Posted October 8, 2007 Share Posted October 8, 2007 substr() function I believe might work. Regards ACE Link to comment https://forums.phpfreaks.com/topic/71900-calculation-and-limiting-decimals/#findComment-364237 Share on other sites More sharing options...
darkfreaks Posted October 8, 2007 Share Posted October 8, 2007 lookup the printr() function its what i use Link to comment https://forums.phpfreaks.com/topic/71900-calculation-and-limiting-decimals/#findComment-364238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.