Please can anyone explain what's happening here?
$num1 = 37.29;
$num2 = 29.83;
$exp1 = round(($num1-$num2)*100); // 746.0 => OK
$exp2 = (($num1-$num2)*100); // 746.0 => OK
$exp1 == $exp2; // false => expected TRUE
746.0 == 746.0; // true => OK
OK, perhaps it is the broken floating point math, but I need the most suitable function anyway.
I'am trying to round_up prices in this way:
1.2345 Eur = 1.24 Eur
1.2567 Eur = 1.26 Eur
but this behavior does me serious headache. Or is there any better way to round up the values? I need this function:
function round_up(float $price, int $decimalPlaces = 2): float {...}
EDIT: I also try the ceiling() function (https://www.php.net/manual/en/function.ceil.php#85430):
$num1 = 37.29;
$num2 = 29.83;
ceiling(7.46, 0.01); // 7.46 => OK
ceiling($num1-$num2, 0.01); // 7.47 => wrong!!!
EDIT2: This works but it's not very intuitive and do the math this way in the whole application would be bad:
ceiling(ceiling($num1, 0.01) - ceiling($num2, 0.01), 0.01); // 7.46 => OK
Thanks