php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34539 tqjs
Submitted: 2005-09-18 05:44 UTC Modified: 2005-09-19 07:34 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: roy dot name at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.1.0RC1 OS: windows
Private report: No CVE-ID: None
 [2005-09-18 05:44 UTC] roy dot name at gmail dot com
Description:
------------
Why the (9.8*3 != 29.4)
see the code may know clear

Reproduce code:
---------------
<?php
$test = 9.8;
if ( $test*3 == 29.4 ) {
	echo 'True';
} else {
	echo 'False'; # This is the out?
} 
# If the value of $test is many others value ,and '29.4' is
# the correct value,the program will out the True;
?>

Expected result:
----------------
Expected result:True


Actual result:
--------------
Actual result:
False

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-18 06:25 UTC] alan_k@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.

-
 [2005-09-19 03:22 UTC] roy dot name at gmail dot com
<?php
$test = 12.4;
if ( $test*3 == 37.2 ) {
	echo 'True';
} else {
	echo 'False'; # This is the out?
} 

?>
If I change the Floating point values,for example:12.4,then,the result is 37.2,and it can output the actual result
 [2005-09-19 07:34 UTC] derick@php.net
It is all still expected behavior, there is no bug here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 14:00:02 2025 UTC