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

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

$
0
0

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;=> 4.5>>> round(4.8 / 5, 1) * 5;=> 5.0>>> round(4.75 / 5, 1) * 5;=> 5.0

If you want you can round() down too like round($number, 1, PHP_ROUND_HALF_DOWN) check the documentation for more information https://www.php.net/manual/en/function.round.php


Viewing all articles
Browse latest Browse all 8

Trending Articles





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