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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 06:01:35 2024 UTC