Bug #72938 [NEW]: Wrong output for intval of floats

From: Date: Thu, 25 Aug 2016 08:10:45 +0000
Subject: Bug #72938 [NEW]: Wrong output for intval of floats
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203531@lists.php.net to get a copy of this message
From:             inggo dot espinosa at gmail dot com
Operating system: Ubuntu 14.04
PHP version:      7.0.10
Package:          Math related
Bug Type:         Bug
Bug description:Wrong output for intval of floats

Description:
------------
When using intval, float conversion is off for some very specific
numbers. Please see my Test script below.

Test script:
---------------
<?php

echo intval(160.70 * 100) . "\n"; // Expected 16070, got 16069
echo intval(150.70 * 100) . "\n"; // Expected 15070, got 15069
echo intval(140.70 * 100) . "\n"; // Expected 14070, got 14069
echo intval(130.70 * 100) . "\n"; // Expected 13070, got 13069
echo intval(120.70 * 100) . "\n"; // Strangely, this gives the correct
value of 12070
echo intval(160.50 * 100) . "\n"; // This also gives the correct value
of 16050
echo intval(160.60 * 100) . "\n"; // This also gives the correct value
of 16060
echo intval(170.70 * 100) . "\n"; // This also gives the correct value
of 17070
echo intval(strval(160.70 * 100)); // This is the workaround that I am
doing for now


Expected result:
----------------
16070
15070
14070
13070
12070
16050
16060
17070
16070

Actual result:
--------------
16069
15069
14069
13069
12070
16050
16060
17070
16070

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



Thread (2 messages)

« previous php.bugs (#203531) next »