Quantcast
Channel: Round DOWN to nearest half integer in PHP - Stack Overflow
Browsing all 8 articles
Browse latest View live

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 Article


Answer 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 Article

Image may be NSFW.
Clik here to view.

Answer 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 Article

Answer by Kiran for Round DOWN to nearest half integer in PHP

echo round($val*2) / 2; // Done

View Article

Answer 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 Article


Answer 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 Article

Answer by Dominic Rodger for Round DOWN to nearest half integer in PHP

$x = floor($x * 2) / 2;

View Article

Round 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

Browsing all 8 articles
Browse latest View live




<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>