#47168 [Opn->Bgs]: printf of floating point variable prints maximum of 40 decimal places
| From: | iliaa@php.net | Date: | Tue, 20 Jan 2009 18:04:28 +0000 |
| Subject: | #47168 [Opn->Bgs]: printf of floating point variable prints maximum of 40 decimal places | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-133076@lists.php.net to get a copy of this message | ||
ID: 47168
Updated by: iliaa@php.net
Reported By: exploringbinary at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: Windows
PHP Version: 5.2.8
New Comment:
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
PHP string formatting functions will not permit float precision beyond
40 characters, this is a hard limit. A notice was however added to
indicate that this is happening.
Previous Comments:
------------------------------------------------------------------------
[2009-01-20 14:55:45] exploringbinary at gmail dot com
Description:
------------
printf will not print more than 40 decimal places, even if the format
specifier asks for more. For example,
<?php
$value = 0.00000000000000011102230246251565404236316680908203125; //
2^-53
printf ("%1.53f",$value); // Prints only 40 decimal places:
0.0000000000000001110223024625156540423632
?>
Contrast this with javascript:
<script type="text/javascript">
var value = 0.00000000000000011102230246251565404236316680908203125;
// 2^-53
var result = value.toFixed(53);
document.write (result); // Prints all 53 decimal places
</script>
I reported a similar bug in Visual Studio, which Microsoft acknowledged
as an error:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=329278
Reproduce code:
---------------
<?php
$value = 0.00000000000000011102230246251565404236316680908203125; //
2^-53
printf ("%1.53f",$value); // Prints only 40 decimal places:
0.0000000000000001110223024625156540423632
?>
Expected result:
----------------
I expect to see all 53 decimal places printed:
0.00000000000000011102230246251565404236316680908203125
Actual result:
--------------
Only 40 decimal places are printed:
0.0000000000000001110223024625156540423632
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47168&edit=1