3 ms·
> I think the reason that 0.1 + 0.2 prints out 0.3 in PHP is that PHP’s algorithm for displaying floating point numbers is less precise than Python’s It's a di
by McGlockenshire 4y ago
> I think the reason that 0.1 + 0.2 prints out 0.3 in PHP is that PHP’s algorithm for displaying floating point numbers is less precise than Python’s
It's a display thing, not an algorithm thing. It rounds by default at a certain length, previously 17 digits.
php > echo PHP_VERSION;
8.2.1
php > $zeropointthree = 0.1 + 0.2;
php > echo $zeropointthree;
0.3
php > ini_set('precision', 100);
php > echo $zeropointthree;
0.3000000000000000444089209850062616169452667236328125
https://www.php.net/manual/en/ini.core.php#ini.precision https://www.php.net/manual/en/ini.core.php#ini.precision