PHP - round() function with PHP_ROUND_HALF_DOWN mode (unexpected behavoir)

444 views Asked by At

Currently I am working with PHP 5.3.29 and the round() function in PHP_ROUND_HALF_DOWN mode to round a specific number.

Here is my code:

function getBetragrabatt($betrag, $rabatt, $ratezahl = false){
    if(!empty($rabatt)){
        $rabatt = str_replace(array(",", "."), array("", ""), $rabatt);
        if($ratezahl >=1)
            $abschlag = ($rabatt / $ratezahl);
        else
            $abschlag = $rabatt;
        $abschlag = floor($abschlag / 100) . '.' . ($abschlag % 100);
        $rabattbetrag = ($betrag - round($abschlag, 0, PHP_ROUND_HALF_DOWN));
    }
    return $rabattbetrag;
}

$rateRabatt = getBetragrabatt(119.95, 100, 18);

echo $rateRabatt;

If I use the code on sandbox (click here) everything works as expected and I get 119.95 as result.

If I use the same code within my IDE or upload it to my server, I get 119.40 as result.

What am I doing wrong? Hope you can help me..

0

There are 0 answers