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
 [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: Sat Sep 21 00:01:27 2024 UTC