php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25864 sprintf error
Submitted: 2003-10-14 09:14 UTC Modified: 2003-10-14 10:04 UTC
From: heppevonhambach at web dot de Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: Irrelevant OS: linux
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: heppevonhambach at web dot de
New email:
PHP Version: OS:

 

 [2003-10-14 09:14 UTC] heppevonhambach at web dot de
Description:
------------
looks like sprintf has problems with big numbers 


Reproduce code:
---------------
$n = 1234567890123;
$nL = 17;
$s = sprintf( "%0{$nL}d",$n );


Expected result:
----------------
00001234567890123

Actual result:
--------------
00000001912276171

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-14 10:01 UTC] tony2001 at phpclub dot net
pay attention:
var_dump($n); will output float(1234567890120).
i.e. your integer were automagically converted to float.
so you need to use:
$s = sprintf( "%0{$nL}.0f",$n );
to get expected result.

look here for more info:
http://www.php.net/manual/en/language.types.integer.php
 [2003-10-14 10:04 UTC] tony2001@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

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 Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 07:01:33 2025 UTC