php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #583 sprintf not allowing zero padding on decimal numbers
Submitted: 1998-07-27 03:26 UTC Modified: 1998-09-10 17:50 UTC
From: stef at moi dot org Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0 Final Release OS: FreeBSD 3.0
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: stef at moi dot org
New email:
PHP Version: OS:

 

 [1998-07-27 03:26 UTC] stef at moi dot org
$foo = 3;
$bar = sprintf("%.2d",$foo);
echo $bar;

should produce "03" not "3".

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-09-10 17:50 UTC] zeev
[jim]
Unfortunately, supporting %.# for decimal numbers isn't
quite trivial -- for example, sprintf("%3.2d", 8) produces
" 08". (Not that this can't or shouldn't be supported,
just making note of the fact that it isn't trivial and
requires handling cases like that.)

[ssb]
PHP's formatter is a bit different from that of libc here.
Everything after the "." in the formatting specifier
applies to the decimal part of a floating-point number,
(or the truncation length for strings).  Won't
sprintf("%02d", $foo) do what you want, or have I
misunderstood your problem?

[zeev]
this has been lingering for too long, Stig's solution works perfectly.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 18:01:31 2024 UTC