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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
35 + 21 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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 Mar 28 22:01:26 2024 UTC