jester626 Posted June 13, 2007 Share Posted June 13, 2007 I am pulling info from a MySQL DB. When I go to use Round like this: echo round($containers,1); It will give me an answer of 5.1 which is mathematically correct. However, I want it to give me an answer to the next highest half (.5) of a container so in this instance I would want the answer of 5.5 not 5.1. Is there a way to round to the next highest half? Thanks in advance Jester Link to comment https://forums.phpfreaks.com/topic/55415-round-question/ Share on other sites More sharing options...
wbartels Posted June 13, 2007 Share Posted June 13, 2007 If I understand correctly this is what you want: Input > Output 5.0 > 5.0 5.1 > 5.5 5.2 > 5.5 5.3 > 5.5 5.4 > 5.5 5.5 > 5.5 5.6 > 6 5.7 > 6 5.8 > 6 5.9 > 6 6.0 > 6 Than this will do the trick: <?php $input = 5.1; $output = ceil($input * 2) / 2; echo $output; ?> Link to comment https://forums.phpfreaks.com/topic/55415-round-question/#findComment-273909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.