|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44110 intval problem with conversion from float to int (without decimal places)
Submitted: 2008-02-13 16:14 UTC Modified: 2008-02-13 16:52 UTC
From: dstuff at brainsware dot org Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 5.2.5 OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: dstuff at brainsware dot org
New email:
PHP Version: OS:


 [2008-02-13 16:14 UTC] dstuff at brainsware dot org
Some float values after multiplication by 100 (for elemination of decimal places) get rounded down by one after running intval() on the result.

Reproduce code:
// prior calculation:
echo intval(70.74 * 100);

// testing for all numbers between 0 and 10 that do not hold the same value after type change
for ($j = 0.00; $j < 10.0; $j = $j + 0.01) {
	$i = ($j);
	if (strval(intval($i * 100)) != strval(($i * 100))) {
		echo $i . ': ' . intval($i*100) . ' | ' . ($i * 100) . '<br />';


Expected result:
Expected value after evaluation: 7047

Actual result:
Actual value after evaluation: 7073


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-13 16:52 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-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 17:01:31 2024 UTC