php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25936 comparing 2 float variables with same value result false
Submitted: 2003-10-21 11:34 UTC Modified: 2003-10-21 11:57 UTC
From: sebastian dot sieburg at partyleader dot de Assigned:
Status: Not a bug Package: Variables related
PHP Version: Irrelevant OS: Linux, BSD, etc. ..
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.
Password:
Status:
Package:
Bug Type:
Summary:
From: sebastian dot sieburg at partyleader dot de
New email:
PHP Version: OS:

 

 [2003-10-21 11:34 UTC] sebastian dot sieburg at partyleader dot de
Description:
------------
set a var using round, the other via value ... compare the vars .. same values but comparision returns false .. tried in php 4.3.1, 5.0.0-dev and 4.1.2 .. same problem in all versions ..

Reproduce code:
---------------
<?php
	$val = 1.11;
	echo "\$val: "; var_dump ($val);

	$p1 = $val * 100;
	$p2 = round ($val * 100);

	$p1 = (float)$p1;
	$p2 = (float)$p2;

	if ($p1 == $p2)
		echo "$p1 == $p2";
	else
		echo "$p1 != $p2";

	echo "\n";
	echo "\$p1: "; var_dump ($p1);
	echo "\$p2: "; var_dump ($p2);

?>

Expected result:
----------------
$val: float(1.11)
111 == 111
$p1: float(111)
$p2: float(111)


Actual result:
--------------
$val: float(1.11)
111 != 111
$p1: float(111)
$p2: float(111)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-21 11:57 UTC] elmicha@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

See <http://de.php.net/manual/de/language.types.float.php>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC