I have a table with a decimal field, which I need to round down.
Here's a data snippet of the table:
number
9.5
9.53
7.25
6.9
9.6
8.0
8.3
8.75
9.0
12.25
12.65
11.0
If a number is between XXX.0 and XXX.5 the number needs to round down to XXX.0 (eg. 8.3 or 12.25 expecting 8.0 or 12.0)
If the number is between XXX.5 and XXX.0 the number needs to round down to XXX.5 (eg. 9.53 or 9.6 expecting 9.5 or 9.5)
Else the number should stay unchanged (eg. 8.0 or 11.0)
Here is my question: How can I define what is in front of the decimal, this can be anything between 0 and 20? I have not found anything similar anywhere... Is there a way to only look at the value after the decimal?
Here is a sample code snipped, where XXX is the unknown part of the decimal number:
if(($number > XXX.0) && ($number < XXX.5))
{ $newNumber = round($number, 0, PHP_ROUND_HALF_DOWN); }
elseif(($number > XXX.5) && ($number < XXX.0))
{ $newNumber = round($number, 0, PHP_ROUND_HALF_DOWN); }
elseif(($number == XXX.5) || ($number == XXX.0))
{ $newNumber = $number; }