Bug #52315 [NEW]: Error in type convert after specific round() operation

From: Date: Mon, 12 Jul 2010 12:41:02 +0000
Subject: Bug #52315 [NEW]: Error in type convert after specific round() operation
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-152298@lists.php.net to get a copy of this message
From:             
Operating system: Ubuntu 8.04
PHP version:      5.2.13
Package:          Math related
Bug Type:         Bug
Bug description:Error in type convert after specific round() operation

Description:
------------
First I perform specific round() operation. Then I convert the number from
float to integer. The result is wrong, the number differs by 1 from what it
should be.

The problem appears not for every number.

Test script:
---------------
    // this works bad:
    $sum = '4926.11';
    $sum = round($sum, 2) * 100;
    var_dump($sum);                // float(492611)

    $sum = (integer) $sum;
    var_dump($sum);                // int(492610)

    // the same round() operation, the other number, works good
    $sum = '426.11';
    $sum = round($sum, 2) * 100;
    var_dump($sum);                // float(42611)

    $sum = (integer) $sum;
    var_dump($sum);                // int(42611)

    // the first numbers, the other round() operation, works good
    $sum = '4926.11';
    $sum = round($sum * 100);
    var_dump($sum);                // float(492611)

    $sum = (integer) $sum;
    var_dump($sum);                // int(492611)





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



Thread (3 messages)

« previous php.bugs (#152298) next »