|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77149 Invalid float to integer
Submitted: 2018-11-14 08:45 UTC Modified: 2018-11-17 00:58 UTC
From: antsokol at mail dot ru Assigned:
Status: Not a bug Package: Math related
PHP Version: 7.2.12 OS: Windows 10 64bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: antsokol at mail dot ru
New email:
PHP Version: OS:


 [2018-11-14 08:45 UTC] antsokol at mail dot ru
Invalid float to integer conversion

Test script:
$price = 76.24;
$price *= 100;
echo $price . PHP_EOL;                 //7624
echo (integer)$price . PHP_EOL;        //7623
echo intval($price) . PHP_EOL;         //7623


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-14 10:13 UTC]
-Status: Open +Status: Not a bug
 [2018-11-14 10:13 UTC]
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:

Thank you for your interest in PHP.

 [2018-11-17 00:58 UTC]
Python and Ruby converts IEEE 754 float values like PHP. You can use round() to get desired integer value from IEEE 754 double precision.
echo (integer)round($price) . PHP_EOL;
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 16:01:29 2024 UTC