[php-src] Issue #20541: Possible round precision issue in PHP 8.4

From: Date: Thu, 20 Nov 2025 16:42:50 +0000
Subject: [php-src] Issue #20541: Possible round precision issue in PHP 8.4
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-251257@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/20541 Author: MelechMizrachi ### Description The following code: ```php <?php var_dump(round( 5, 12), round((float) 5, 12), round(5.0, 12)); var_dump(round( 5, 15), round((float) 5, 15), round(5.0, 15)); var_dump(round( 50, 12), round((float) 50, 12), round(50.0, 12)); var_dump(round( 500, 12), round((float) 500, 12), round(500.0, 12)); var_dump(round( 5000, 12), round((float) 5000, 12), round(5000.0, 12)); var_dump(round( 50000, 12), round((float) 50000, 12), round(50000.0, 12)); var_dump(round( 50000, 11), round((float) 50000, 11), round(50000.0, 11)); ``` Resulted in this output: ``` float(5) float(5) float(5) float(5) float(5.000000000000001) float(5.000000000000001) float(50) float(50) float(50) float(500) float(500) float(500) float(5000) float(5000.000000000001) float(5000.000000000001) float(50000) float(50000) float(50000) float(50000) float(50000.00000000001) float(50000.00000000001) ``` But I expected this output instead: ``` float(5) float(5) float(5) float(5) float(5) float(5) float(50) float(50) float(50) float(500) float(500) float(500) float(5000) float(5000) float(5000) float(50000) float(50000) float(50000) float(50000) float(50000) float(50000) ``` You'll notice the additional 0's ending in 1 only for the numbers where the length of the digits to the left of the decimal plus the precision is one more than the PHP_FLOAT_DIG (15). I think this is a bug, but I would love some help figuring this one out if it not. https://3v4l.org/T5M4U ### PHP Version ```plain PHP 8.4.14 (cli) (built: Nov 7 2025 13:49:30) (NTS) Copyright (c) The PHP Group Zend Engine v4.4.14, Copyright (c) Zend Technologies with Zend OPcache v8.4.14, Copyright (c), by Zend Technologies with ddtrace v1.13.1, Copyright Datadog, by Datadog and PHP 8.4.7 (cli) (built: May 6 2025 14:12:45) (ZTS Visual C++ 2022 x64) Copyright (c) The PHP Group Zend Engine v4.4.7, Copyright (c) Zend Technologies with Xdebug v3.4.3, Copyright (c) 2002-2025, by Derick Rethans ``` ### Operating System _No response_

« previous php.bugs (#251257) next »