php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55720 *printf problem formatting numbers
Submitted: 2011-09-18 15:28 UTC Modified: 2011-09-18 15:31 UTC
From: php_nospam at ramihyn dot sytes dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: any
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php_nospam at ramihyn dot sytes dot net
New email:
PHP Version: OS:

 

 [2011-09-18 15:28 UTC] php_nospam at ramihyn dot sytes dot net
Description:
------------
*printf functions have a problem correctly formatting numbers

Problem is reproducible with php 5.3.8 (win32) and php 5.3.6 (linux x86).
Numbers output were different on my two machines, but stayed the same on each machine.

Test script:
---------------
<?php
printf("%0.31f %0.31f %0.31f",
  3.14159265359793238462643383279,
  14159265359793238462643383279.0,
  1.3
);
?>

Expected result:
----------------
3.1415926535979323846264338327900 14159265359793238462643383279.0000000000000000000000000000000 1.3000000000000000000000000000000

Actual result:
--------------
3.1415926535979323830360954161733 14159265359793237514732437504.0000000000000000000000000000000 1.3000000000000000444089209850063


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-18 15:31 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2011-09-18 15:31 UTC] pajoye@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 20:01:35 2025 UTC