Search code examples
phpfloating-point-precision

php sum zero value to float number


I'm in trouble with this:

$price = 26,20;
$increase = 0,00;
$decrease = 0,00;

$result = ($price + $increase - $decrease);  

Result becomes 26 instead of 26,20

Any idea?

Thnx!


Solution

  • You can use number_format in case you need comma as decimal separator, see example below:

    $price = 26.20;
    $increase = 0.00;
    $decrease = 0.00;
    
    $result = ($price + $increase - $decrease);
    echo number_format($result , 2, ',', '');