php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75644 round(362.42499999999995, 2) gives incorrect result
Submitted: 2017-12-06 22:47 UTC Modified: -
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:3 (100.0%)
From: markamery at btinternet dot com Assigned:
Status: Open Package: Math related
PHP Version: 7.1.12 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: markamery at btinternet dot com
New email:
PHP Version: OS:

 

 [2017-12-06 22:47 UTC] markamery at btinternet dot com
Description:
------------
Even though 362.42499999999995 is less than 362.425 (i.e. the internally-stored IEEE-754 representation of 362.42499999999995 has a value less than 362.425), round(362.42499999999995, 2) gives 362.43

It should give 362.42

Test script:
---------------
<?php
$x = 362.42499999999995;
echo $x . "\n";
echo round($x, 2) . "\n";
ini_set('precision', 999);
echo $x . "\n";
echo round($x, 2) . "\n";


Expected result:
----------------
362.425
362.42
362.424999999999954525264911353588104248046875
362.42000000000001591615728102624416351318359375


Actual result:
--------------
362.425
362.43
362.424999999999954525264911353588104248046875
362.43000000000000682121026329696178436279296875


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Oct 19 19:01:25 2018 UTC