php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #42432 large numbers ending with zeroes
Submitted: 2007-08-26 19:59 UTC Modified: 2007-11-22 23:45 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: zoxx at konto dot pl Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.3 OS: FreeBSD
Private report: No CVE-ID: None
 [2007-08-26 19:59 UTC] zoxx at konto dot pl
Description:
------------
Bug related with Bugs #41811, #41152.

It's not really round() problem but string conversion made by echo or concatenation with string. 

It is serious bug with strong consequences:
- php4 was free with that 'feature' so old correctly working scripts could fail with php5 
- data that is inserted to mysql with exponent notation to mysql integer fields is cutted to digits (so if you insert 1.41E+7 '1' integer is inserted instead)
- data could be not displayed correctly, not correctly inserted to files or passed to external systems (and so on...)
- it is unrelated with 'precision' php.ini configuration item, so unexpected by programmer

Reproduce code:
---------------
<form action="testval.php" method=POST>
<input type=text name=val>
</form>
<?php
echo $val*100.0;
?>

Expected result:
----------------
input: 410000
output: 41000000

Actual result:
--------------
input: 410000
output: 4.1E+7

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-27 08:45 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2007-08-27 09:23 UTC] zoxx at konto dot pl
It is not described in manual.


Additional tests (FreeBSD, Windows XP SP 1):

<?php
	echo 4100000*1.0;
?>

expected result: 4100000
actual result: 4.1E+6

Notice: 
1) it is not float precision problem
2) script is working correctly on php4
 [2007-08-27 09:32 UTC] jani@php.net
It's not working any differently than in PHP 4. Internally it's the same value. Reclassified.
 [2007-08-27 09:49 UTC] zoxx at konto dot pl
The problem is not internal representation, but float -> string conversion made while 'echo' or while inserting to a string (like $txt="value: $val";).

It is not working same as in php4 (I have tested that scripts with php4 too - the result is correct there: no exponent notation used).
 [2007-10-22 16:54 UTC] rbro at hotmail dot com
I am running into this same issue.  I just added a comment on bug 43053 which is describing the same issue.
 [2007-11-21 17:19 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Floating point numbers can be converted using the exponential notation (4.1E+6)."
 [2007-11-22 23:45 UTC] zoxx at konto dot pl
fine.. but it wasn't documentation problem

Anyway we have solved it in our scripts, where it was most urgent, by adding special function to convert strings that may contain exponental numbers because this bug - eg. before sending query to mysql (it was easy because we have special class to call databases, but if you use mysql_something functions everywhere you are lucky less...):

	/**
	 * function ConvExponent($str)
	 * This function replaces exponent notation of float values in string
	 */
	function ConvExponent($str)
	{
		return preg_replace('#(\d+)\.(\d+)E(\+|\-)(\d+)#sie', 'sprintf(\'%F\',floatval($0))', $str);
	}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 04:00:03 2025 UTC