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:4
Avg. Score:4.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.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
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
35 + 19 = ?
Subscribe to this entry?

 
 [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-2019 The PHP Group
All rights reserved.
Last updated: Mon Oct 21 08:01:27 2019 UTC