peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.31k stars 201 forks source link

Addition of variable not giving perfect value () [Floating point error] #1096

Closed BKSoftCraft closed 1 year ago

BKSoftCraft commented 1 year ago

<?php
$sum = 296.95 + 297.95 + 41.3;
echo $sum;      // Print Sum :636.1999999999999
// In Core PHP work fine
?>
jakubmisek commented 1 year ago

It's the exact opposite - PHP is not giving the exact value. It tries to hide the floating-point-number error implicitly.

If you use debug_zval_dump($sum) in PHP, you'd see the correct value.

We don't do this rounding inside echo.