I have a basic 5 star rating system based on user submissions. depending on the rating, a particular image is shown.
$user_rating
contains the rating number to one decimal place.
There are 'star' images with
0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0
in the file names.
I need whatever number is contained in $user_rating to be rounded down to the nearest value above and stored in a new variable $star_rating
. The numbers can never be rounded up. Even if $user_rating
is 4.9, $star_rating
should be 4.5.
Can someone help me achieve this? Thanks
EDIT - using this but just returns original value - in this case 3.8
$star_rating = $user_rating;
function roundToHalf($star_rating) {
$temp = $star_rating * 10;
$remainder = $star_rating % 5;
return ($temp - $remainder) / 10;
}