|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25562 Float to String to Float conversion error
Submitted: 2003-09-16 15:34 UTC Modified: 2003-09-16 16:24 UTC
From: daseymour at 3hc dot org Assigned:
Status: Not a bug Package: Math related
PHP Version: * OS: *
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.
Bug Type:
From: daseymour at 3hc dot org
New email:
PHP Version: OS:


 [2003-09-16 15:34 UTC] daseymour at 3hc dot org
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!"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-16 16:00 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Floating point values are handled with a limited precision.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 20 20:03:44 2023 UTC