Round number up to `.49` or `.99`

Issue

I’m trying to round number like this :

5,24785 => 5,49
5,74536 => 5,99
5,00000 => 5,00

I tried with https://php.net/round

But this return

5,24785 => 5,24
5,74536 => 5,74
5,00000 => 5,00

A php function can do it or I need to round up then remove 0.01 ?

Do you have some clues ?

Solution

You need using custom round function for this. Because rounding to 0.49 is not standard way.

    function rounder($num){
    $fln= $num-floor($num);
    if ($fln>0 and $fln<0.5) $fln=0.49;
    else $fln=0.99;

    return floor($num)+$fln;
    }
    echo rounder(5.24882);

Answered By – Elvin Haci

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published