|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62385 intval gives wrong result with float value
Submitted: 2012-06-21 23:41 UTC Modified: 2012-06-22 00:33 UTC
From: iam4webwork at hotmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.4.4 OS:
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: iam4webwork at hotmail dot com
New email:
PHP Version: OS:


 [2012-06-21 23:41 UTC] iam4webwork at hotmail dot com
A float value of 19.99 * 100 when passed to intval becomes 1998 unless embedded in 
a string.

Test script:
$amount = 19.99 * 100;
$test2 = intVal($amount);
$test3 = intVal("$amount");

echo $test2 . "<br />\n";
echo $test3 . "<br />\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-21 23:43 UTC] iam4webwork at hotmail dot com
It only works correctly if you round the float value and then pass it to intval.
 [2012-06-22 00:33 UTC]
-Status: Open +Status: Not a bug
 [2012-06-22 00:33 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.

PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC