php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80973 round() fail if ini 'precision' value > 16
Submitted: 2021-04-21 02:55 UTC Modified: 2021-04-21 08:17 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: pavlusha23 at gmail dot com Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 8.0.3 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pavlusha23 at gmail dot com
New email:
PHP Version: OS:

 

 [2021-04-21 02:55 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-21 08:17 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2021-04-21 08:17 UTC] nikic@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 18:01:31 2024 UTC