php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39262 intval(0.1+0.7) function failed
Submitted: 2006-10-26 08:43 UTC Modified: 2006-10-26 08:55 UTC
From: cjjer at hotmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.1.X OS: windows2k
Private report: No CVE-ID: None
 [2006-10-26 08:43 UTC] cjjer at hotmail dot com
Description:
------------
intval function failed ;for intval((0.1+0.7)*10) not is 8 ,but 7.

Reproduce code:
---------------
1
2
3
4
5
6
7
7
9
9
10


Expected result:
----------------
1
2
3
4
5
6
7
8
9
9
10


Actual result:
--------------
1
2
3
4
5
6
7
7
9
9
10


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-26 08:48 UTC] cjjer at hotmail dot com
[code]
for($i=0.0; $i<1;){
	echo intval(($i+0.10)*10.0).'<br/>'; 
	$i=$i+0.1;
}
[/code]
 [2006-10-26 08:55 UTC] johannes@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://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC