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 Quote Link to comment 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; } Quote Link to comment Share on other sites More sharing options...
jwk811 Posted February 19, 2007 Author Share Posted February 19, 2007 thanks, nothing any simpler? Quote Link to comment 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 ?> Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.