Bug #49187 [Com]: Misbehaving function : intval ()
| From: | spam2 at rhsoft dot net | Date: | Wed, 09 May 2018 12:00:09 +0000 |
| Subject: | Bug #49187 [Com]: Misbehaving function : intval () | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215176@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=49187&edit=1
ID: 49187
Comment by: spam2 at rhsoft dot net
Reported by: belanger dot b at gmail dot com
Summary: Misbehaving function : intval ()
Status: Not a bug
Type: Bug
Package: *Math Functions
Operating System: Linux
PHP Version: 5.2.5
Block user comment: N
Private report: N
New Comment:
> This bug still exists in PHP 7.1.14
it is not a bug and hence it can't be fixed - read the comment before yours
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
Previous Comments:
------------------------------------------------------------------------
[2018-05-09 11:48:48] belanger dot b at gmail dot com
This bug still exists in PHP 7.1.14.
$ php -a
Interactive shell
php > echo phpversion();
7.1.14
php > echo intval(9.95 * 100);
994
------------------------------------------------------------------------
[2009-08-07 10:23:17] rasmus@php.net
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
Thank you for your interest in PHP.
------------------------------------------------------------------------
[2009-08-07 07:54:07] jani@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP --
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php
If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
------------------------------------------------------------------------
[2009-08-07 05:51:09] belanger dot b at gmail dot com
Tested it with all values from previously rejected or ignored similar bug submissions (code and
execution here) :
http://www.benlg.com/test.php
P.S.: intval('9.95'*100) == intval(9.95*100) == 994
------------------------------------------------------------------------
[2009-08-07 05:20:11] belanger dot b at gmail dot com
Description:
------------
intval is not returning the correct value for '995'
echo number_format('9.95'*100,0,'',''); // output 995
echo intval('9.95'*100); // output 994
Sorry but the most up to date server at my disposition is version 5.2.5
POSSIBLY RELATED REFUSED BUGS...
found by me :
http://bugs.php.net/bug.php?id=1960 (set to
closed)
found by system :
http://bugs.php.net/bug.php?id=37554 (set to
bogus)
http://bugs.php.net/bug.php?id=39900 (set to
bogus)
Reproduce code:
---------------
echo number_format('9.95'*100,0,'','')
.' and '. number_format('1.16'*100,0,'','')
."\n". intval('9.95'*100);
.' and '. intval('1.16'*100);
Expected result:
----------------
995 and 116
995 and 116
Actual result:
--------------
995 and 116
994 and 115
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=49187&edit=1