↧
Answer by Oleksii Tarbeiev for Round DOWN to nearest half integer in PHP
Here is the solution for integer input.tests: 124->100, 125->150, 126->150, 187->200, 974->950, 975->1000, 980->1000function roundHalf($num) { $rounded = round($num / 50) * 50;...
View ArticleAnswer by xavadu for Round DOWN to nearest half integer in PHP
You can do it on that way round($number / 5, 1) * 5 the second parameter in the round() is the precision.Example with $number equal to 4.6, 4.8 and 4.75>>> round(4.6 / 5, 1) * 5;=>...
View ArticleAnswer by Berserk for Round DOWN to nearest half integer in PHP
A easy solution is to use modulo operator (fmod() function), like this :function roundDown($number, $nearest){ return $number - fmod($number, $nearest);}var_dump(roundDown(7.778,...
View ArticleAnswer by Kiran for Round DOWN to nearest half integer in PHP
echo round($val*2) / 2; // Done
View ArticleAnswer by chuyen nha for Round DOWN to nearest half integer in PHP
From my job's requirements. I put an function to do this. Hope you can view it as a reference:function round_half_five($no) { $no = strval($no); $no = explode('.', $no); $decimal =...
View ArticleAnswer by tzaman for Round DOWN to nearest half integer in PHP
I'm assuming PHP has a floor function: floor($num * 2) / 2 ought to do it.
View ArticleAnswer by Dominic Rodger for Round DOWN to nearest half integer in PHP
$x = floor($x * 2) / 2;
View ArticleRound DOWN to nearest half integer in PHP
I need a PHP function that will take a float and round it down to the nearest half (x.0 or x.5). I found other functions that will round to the nearest fraction, but they round both ways.The function I...
View Article
More Pages to Explore .....