jwk811 Posted February 19, 2007 Share Posted February 19, 2007 i forgot how to do this, but i need to make sure it rounds only up and to the 10 Link to comment https://forums.phpfreaks.com/topic/39119-round-up-to-10/ Share on other sites More sharing options...
corbin Posted February 19, 2007 Share Posted February 19, 2007 function roundtotens($num) { if($num % 10) { } else { $mod = $num % 10; $add = 10 - $mod; $num += $add; $num = round($num); if($num % 10) { $num -= 1; } } return $num; } Link to comment https://forums.phpfreaks.com/topic/39119-round-up-to-10/#findComment-188409 Share on other sites More sharing options...
jwk811 Posted February 19, 2007 Author Share Posted February 19, 2007 thanks, nothing any simpler? Link to comment https://forums.phpfreaks.com/topic/39119-round-up-to-10/#findComment-188411 Share on other sites More sharing options...
bluebyyou Posted February 19, 2007 Share Posted February 19, 2007 try the ceil() function <?php echo ceil(9.123423); // Value would be 10 ?> Link to comment https://forums.phpfreaks.com/topic/39119-round-up-to-10/#findComment-188417 Share on other sites More sharing options...
jwk811 Posted February 19, 2007 Author Share Posted February 19, 2007 yeah that was it! thanks! edit: actually that just goes up one integar Link to comment https://forums.phpfreaks.com/topic/39119-round-up-to-10/#findComment-188418 Share on other sites More sharing options...
jwk811 Posted February 19, 2007 Author Share Posted February 19, 2007 function roundtotens($num) { if($num % 10) { } else { $mod = $num % 10; $add = 10 - $mod; $num += $add; $num = round($num); if($num % 10) { $num -= 1; } } return $num; } if that rounds up to 10 how can i make it round down to 10 instead? Link to comment https://forums.phpfreaks.com/topic/39119-round-up-to-10/#findComment-188427 Share on other sites More sharing options...
bluebyyou Posted February 19, 2007 Share Posted February 19, 2007 I dont think that function works. Im pretty sure these do.. <?php $num = 123; function round_up_ten($num) { $mod = $num % 10; $add = 10 - $mod; $num += $add; echo $num; } function round_dwn_ten($num) { $mod = $num % 10; $add = 10 - (10 - $mod); $num -= $add; echo $num; } round_up_ten($num); // Should be 130 round_dwn_ten($num); // Should be 120 ?> Link to comment https://forums.phpfreaks.com/topic/39119-round-up-to-10/#findComment-188440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.