php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1259 Double in a string comparision bug after converting with strval and intval
Submitted: 1999-03-23 01:03 UTC Modified: 1999-03-23 07:41 UTC
From: mlemos at acm dot org Assigned:
Status: Closed Package: Compile Failure
PHP Version: 3.0.7 OS: Any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mlemos at acm dot org
New email:
PHP Version: OS:

 

 [1999-03-23 01:03 UTC] mlemos at acm dot org
The following script should demonstrate that if you have a floating point
number in a string and then convert it with intval and strval, PHP says
they are the same where they shouldn't be.

<?
 $value="1.";
 echo "(\"$value\"==strval(intval(\"$value\")))=",$value==strval(intval($value))," intval(\"$value\")=",intval($value),"\n";
 $value=".1";
 echo "(\"$value\"==strval(intval(\"$value\")))=",$value==strval(intval($value))," intval(\"$value\")=",intval($value),"\n";
 $value="1.0";
 echo "(\"$value\"==strval(intval(\"$value\")))=",$value==strval(intval($value))," intval(\"$value\")=",intval($value),"\n";
 $value="1";
 echo "(\"$value\"==strval(intval(\"$value\")))=",$value==strval(intval($value))," intval(\"$value\")=",intval($value),"\n";
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-03-23 07:41 UTC] zeev
That example is way too cryptic.  I doubt there is a bug here, but if there is, demonstrate it in a simple and concise manner instead of this gobblygook.
---
The behavior you claim you see is indeed existant, but it's not
a bug, but an intended behavior.  A much shorter and elegant
way to demonstrate the bug in its essence, would be:
print (string) 1.;
which would, in turn, generate the output:
1
and same goes for
print (string) 1.0000;

PHP's string conversion routines supress any trailing zeros, very
much on purpose.  If you want to force a certain amount of decimal
digits, use printf() or sprintf() instead of echo or print.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 10 20:01:29 2024 UTC