php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73290 intval, floor returns invalid result
Submitted: 2016-10-11 11:56 UTC Modified: 2016-10-11 12:27 UTC
From: drtzack at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.0.11 OS: Ubuntu 16.04 x64
Private report: No CVE-ID: None
 [2016-10-11 11:56 UTC] drtzack at gmail dot com
Description:
------------
intval(floatval("139.20") * 100) returns invalid result

Test script:
---------------
intval(floatval("139.20") * 100) returns invalid result

Expected result:
----------------
13920

Actual result:
--------------
13919

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-11 12:27 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-10-11 12:27 UTC] cmb@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://www.floating-point-gui.de/

Thank you for your interest in PHP.

You can see what actually happens, if you set the precision to
a high value, see <https://3v4l.org/JvKdr>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 15:01:32 2024 UTC