Ask a Question related to PHP Development, Design and Development.
-
daseymour at 3hc dot org #1
#25562 [NEW]: Float to String to Float conversion error
From: daseymour at 3hc dot org
Operating system: [Win 2000 SP4] and [Win XP SP1]
PHP version: 4.3.3
PHP Bug Type: Math related
Bug description: Float to String to Float conversion error
Description:
------------
When I convert a large float value to a string and then back to a float,
the original and the resulting values are not equal.
Note: I looked for this error in the bug list, but did not find one with
the current stable release of PHP (4.3.3).
Thanks in advance.
Reproduce code:
---------------
// Create some large number
$testStart = (float) unserialize("d:1125899906842624;");
// Output value
echo "Before string conversion: $testStart <br>\n";
// Convert value to string
$testString = (string) $testStart;
// Output string
echo "After string conversion: $testString <br>\n";
// Convert string back to a value
$testEnd = (float) $testString;
// Output value
echo "After float conversion: $testEnd <br>\n";
// Compare the two values
if( $testStart == $testEnd ) {
echo "<br>\nThe two values are equal.<br>\n";
} else {
echo "<br>\nThe two values appear to be the same, but are <u>not</u>
equal!<br>\n";
};
Expected result:
----------------
I expect to see "The two values are equal."
Actual result:
--------------
I am getting "The two values appear to be the same, but are not equal!"
--
Edit bug report at [url]http://bugs.php.net/?id=25562&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=25562&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=25562&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=25562&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=25562&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=25562&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=25562&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=25562&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=25562&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=25562&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=25562&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=25562&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=25562&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=25562&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=25562&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=25562&r=gnused[/url]
daseymour at 3hc dot org Guest
-
#39126 [NEW]: String->float->String conversion behavior
From: bobson at rpg dot pl Operating system: Linux PHP version: 5CVS-2006-10-11 (snap) PHP Bug Type: Unknown/Other Function... -
help float to string
try the sprintf print sprint("%.02f", $f); if I'm not rong; -----Original Message----- From: perl@swanmail.com -
#25562 [Opn->Bgs]: Float to String to Float conversion error
ID: 25562 Updated by: helly@php.net Reported By: daseymour at 3hc dot org -Status: Open +Status: ... -
How to convert string to float?
i want to covert a querystring to float number in asp. what function should i use? i know cint() can convert string to int but how about float? -
preventing string conversion to float.
It has been a long time since I touched any perl, and I am having a problem with parsing a text file. I need to pull out a string in the form...



Reply With Quote

