webdancer Posted December 19, 2010 Share Posted December 19, 2010 I am trying to take a number (three for example) and want to round it to five, or sixty-seven up to seventy. I looked at round and ceil, but those don't seem like they are the right things. Thanks, Joseph Link to comment https://forums.phpfreaks.com/topic/222111-rounding-a-variable-to-the-next-5/ Share on other sites More sharing options...
johnny86 Posted December 19, 2010 Share Posted December 19, 2010 function ceilTo($num, $to) { return ceil($num / $to) * $to; } echo ceilTo(12, 5); // Prints: 15 echo ceilTo(121, 5); // Prints 125 echo ceilTo(120, 5); // Prints 120 Link to comment https://forums.phpfreaks.com/topic/222111-rounding-a-variable-to-the-next-5/#findComment-1149165 Share on other sites More sharing options...
webdancer Posted December 19, 2010 Author Share Posted December 19, 2010 Awesome, that works great. Thanks a lot, Joseph Link to comment https://forums.phpfreaks.com/topic/222111-rounding-a-variable-to-the-next-5/#findComment-1149170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.