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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: drtzack at gmail dot com
New email:
PHP Version: OS:

 

 [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: Fri Dec 13 07:01:28 2024 UTC