Bug #80973 [Opn->Nab]: round() fail if ini 'precision' value > 16

From: Date: Wed, 21 Apr 2021 08:17:08 +0000
Subject: Bug #80973 [Opn->Nab]: round() fail if ini 'precision' value > 16
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233534@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80973&edit=1 ID: 80973 Updated by: nikic@php.net Reported by: pavlusha23 at gmail dot com Summary: round() fail if ini 'precision' value > 16 -Status: Open +Status: Not a bug Type: Bug Package: *Math Functions Operating System: Linux PHP Version: 8.0.3 Block user comment: N Private report: N New Comment: precision is a pure display property, it has no effect on round(). Use precision=-1 if you want to print with the smallest precision that allowed a round-trip for that particular number. Large hardcoded precisions are generally not useful, as they will print digits that are beyond the accuracy of floating point numbers. Previous Comments: ------------------------------------------------------------------------ [2021-04-21 02:55:53] pavlusha23 at gmail dot com Description: ------------ round() function fail if ini 'precision' value > 16 Test script: --------------- <?php // Default ini value ini_set('precision','14'); echo round(23.879999999999999, 2)."\n"; ini_set('precision','16'); echo round(23.879999999999999, 2)."\n"; ini_set('precision','17'); echo round(23.879999999999999, 2); Expected result: ---------------- 23.88 23.88 23.88 Actual result: -------------- 23.88 23.88 23.879999999999999 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80973&edit=1

« previous php.bugs (#233534) next »