Bug #77197 [NEW]: rounding problem
| From: | php_bug at sport-sachsenhausen dot de | Date: | Sun, 25 Nov 2018 13:00:09 +0000 |
| Subject: | Bug #77197 [NEW]: rounding problem | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-218125@lists.php.net to get a copy of this message | ||
From: php_bug at sport-sachsenhausen dot de
Operating system: Linux
PHP version: 7.2.12
Package: *Math Functions
Bug Type: Bug
Bug description:rounding problem
Description:
------------
rounding function not as expected
Test script:
---------------
# tested PHP 5.2, 5.3, 5.4, 5.5, 5.6, 7.0, 7.2.12
for( $i = 0; $i < 100; $i += 0.001 ) {
$r_0 = round( $i );
$r_up = round( $i, 2, PHP_ROUND_HALF_UP );
$r_down = round( $i, 2, PHP_ROUND_HALF_DOWN );
# a) missing values
# Line 7- 8: 0,085 + 0,095
# Line 73-74: 0,765 - 0,995
# Line 78-79: 1,055 - 4,965
# Line 81-82: 5,005 - 9,795
# Line 83-84: 9,825 - 18,755
# Line 92-93: 18,855 - 38,885
# Line 97-98: 38,945 - 76,225
# Line 101+ : 76,235 - 99,995
if( $r_up == $r_down ) continue; // comment out... -> attention!
producing 99.999 lines
# see lines: 1.461 - 4.836, 5.137 - 9.723, 9.905 - 10.000, 10.717 -
18.396,
# 19.215 - 38.703, 39.133 - 76.139, 76.349 - 99.999
echo 'Line ' . $count++ . "| {$i} | round 0: {$r_0} | half up: {$r_up}
| half down: {$r_down} <br>";
}
--
Edit bug report at https://bugs.php.net/bug.php?id=77197&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77197&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77197&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77197&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77197&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77197&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77197&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77197&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77197&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77197&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77197&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77197&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77197&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77197&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77197&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77197&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77197&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77197&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77197&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77197&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77197&r=mysqlcfg