|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48462 sprintf error when multiplying float and displaying digit
Submitted: 2009-06-03 17:03 UTC Modified: 2009-06-04 14:25 UTC
Avg. Score:4.0 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: courtois at nouvo dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.9 OS: XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: courtois at nouvo dot com
New email:
PHP Version: OS:


 [2009-06-03 17:03 UTC] courtois at nouvo dot com
This a followup to bug #48455 which has been closed.

I observed same bug with different values.

I'm affraid rasmus' answer is incorrect.

3498 is represented with 12 bits. A float holds 24 bits which is far enough to contain 3498 without any single bit of precision loss.

Anyway, the same program in C works fine:

#include <stdio.h>

   float f;

   printf("%6d %f\n",(int)f,f);

thus the problem is NOT with the float representation.

Moreover the following script should return twice the same thing:


print "x:".$x." sprintf:".sprintf('%d',$x);

but the unexpected result is:

x:3498 sprintf:3497

If the first conversion from float to string works fine, why doesn't the second conversion work ?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-04 14:25 UTC]
Your C program is not same as what PHP does, try change the float to 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Jun 07 12:03:41 2023 UTC