Bug #75644 [NEW]: round(362.42499999999995, 2) gives incorrect result

From: Date: Wed, 06 Dec 2017 22:47:35 +0000
Subject: Bug #75644 [NEW]: round(362.42499999999995, 2) gives incorrect result
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212986@lists.php.net to get a copy of this message
From:             markamery at btinternet dot com
Operating system: Ubuntu
PHP version:      7.1.12
Package:          Math related
Bug Type:         Bug
Bug description:round(362.42499999999995, 2) gives incorrect result

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


-- 
Edit bug report at https://bugs.php.net/bug.php?id=75644&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=75644&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=75644&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=75644&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=75644&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=75644&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=75644&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=75644&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=75644&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=75644&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=75644&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=75644&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=75644&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=75644&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75644&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=75644&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=75644&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=75644&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75644&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=75644&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=75644&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#212986) next »