php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23780 Number comparision fails
Submitted: 2003-05-23 09:54 UTC Modified: 2003-05-23 10:17 UTC
From: walovaton at yahoo dot com dot mx Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.3.1 OS: Linux
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: walovaton at yahoo dot com dot mx
New email:
PHP Version: OS:

 

 [2003-05-23 09:54 UTC] walovaton at yahoo dot com dot mx
When I'm trying to compare two numbers, some times I get not expected results.  Specially with float precision numbers.

In my case:

$value1 = 58.6;
$value2 = 58.6;

if ($value1 > $value2) {
  // PHP Bug!
  // This expresion seems to be true for some reason
  // The expected result is false, isn't it??
}

This happens comparing the numbers as floats or as strings.

It is important to say that $value1 is a value entered by the user into a form input (a validation number) and $value2 is the addition of several fields and such addition must be equal to $value1 in order to be accepted by the application.


I hope this is clear enough for you.


-William

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-23 10:17 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Your sample works fine, have a look at the section in our manual about floats. Not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 10:01:28 2024 UTC