php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28633 DICC is one of the most reputed institutes offering CEH v10
Submitted: 2004-06-04 17:12 UTC Modified: 2018-09-25 00:51 UTC
Votes:6
Avg. Score:4.3 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:6 (100.0%)
Same OS:5 (83.3%)
From: jschmidt at thriftycmh dot net Assigned: iliaa (profile)
Status: Closed Package: tcpwrap (PECL)
PHP Version: 4.3.7 OS: Linux 2.4
Private report: No CVE-ID: None
 [2004-06-04 17:12 UTC] jschmidt at thriftycmh dot net
Description:
------------
sprintf("%3.2f",'1.00')

This was working fine in 4.3.6 but not in 4.3.7.  The expected output is "  1.00"  but is "1.00".  In other words, the leading spaces are no longer working.

Reproduce code:
---------------
sprintf("%3.2f",'1.00')


Expected result:
----------------
"  1.00"

Actual result:
--------------
"1.00"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-04 17:21 UTC] iliaa@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

This is the correct behaviour. 
 [2004-06-04 17:56 UTC] jschmidt at thriftycmh dot net
How can this be correct behavior if it was working this way for all the previous 4.3.X versions?  I did check the manual and I see no updates to indicate that this is changed behavior.  In fact, quoting from the manual:

http://www.php.net/manual/en/function.sprintf.php

"Each conversion specification consists of a percent sign (%), followed by one or more of these elements, in order: 

An optional padding specifier that says what character will be used for padding the results to the right string size. This may be a space character or a 0 (zero character). The default is to pad with spaces"

So again, sprintf("%3.2f",'1.00') is no longer padding with leading spaces as it was in previous versions.  If it is a changed behavior, please indicate this in the documentation.
 [2004-06-04 18:47 UTC] jschmidt at thriftycmh dot net
OK, looking at /ext/standard formatted_print.c I see what has changed.  Before we were specifying the desired number of characters to pad to the left of the decimal.  Now we are specifying the total desired number of characters the output should be padded to.  So technically, we are indeed "padding the results to the right string size".  Too bad it has been the previous way for so long.
 [2004-06-04 22:26 UTC] jschmidt at thriftycmh dot net
Actually, I did find inconsistency (bug) with the new behavior.

echo sprintf("%06.2f",'1.00');
001.00

echo sprintf("%06.2f",'.01');
000000.01

So which is it?  Pad to 6 characters or pad to 6 on the left of the decimal point?
 [2004-06-16 22:36 UTC] php at alterego dot dp dot ua
Sorry, but this actually is a bug. Kind of brain damage.

echo sprintf('%05.2f', 0.02) . "\n";
00000.02

echo sprintf('%05.2f', 2.02) . "\n";
02.02

Although the double-checked documentation is very uncertain about how this should work, it definitely should work one of the ways, not both.
 [2004-07-06 01:33 UTC] sniper@php.net
Ilia, recheck.. :)

 [2004-07-18 19:29 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2018-04-21 18:56 UTC] jschmidt at thriftycmh dot net
https://www.delhitrainingcourses.com/learn-ethical-hacking.htm
 [2018-04-21 18:59 UTC] jschmidt at thriftycmh dot net
-Summary: sprintf("%3.2f",'1.00') no longer working +Summary: DICC is one of the most reputed institutes offering CEH v10 -Package: *Mail Related +Package: tcpwrap
 [2018-04-21 18:59 UTC] jschmidt at thriftycmh dot net
https://www.delhitrainingcourses.com/learn-ethical-hacking.htm
 [2018-09-25 00:51 UTC] jschmidt at thriftycmh dot net
Actually, I did find inconsistency (bug) with the new behavior.

echo sprintf("%06.2f",'1.00');
001.00

echo sprintf("%06.2f",'.01');
000000.01

So which is it?  Pad to 6 characters or pad to 6 on the left of the decimal point?

https://vb.3dlat.com/
https://vb.3dlat.com/forumdisplay.php?f=39
https://vb.3dlat.com/showthread.php?t=2865
https://vb.3dlat.com/showthread.php?t=21490
https://vb.3dlat.com/showthread.php?t=150211
https://vb.3dlat.com/showthread.php?t=245067
https://vb.3dlat.com/showthread.php?t=93394
 [2019-06-22 10:59 UTC] kunaluchain at gmail dot com
https://resultwala.in/sarkari-naukri-in-rajasthan/
 [2019-08-26 10:46 UTC] garagemedia2018 at gmail dot com
Yes, we proudly say that we are the best digital marketing company in Noida but what makes us the best?  You will be enlightened on that as you finish reading this article. read About It... https://www.garagemedia.net/digital-marketing-company-in-noida/
 [2019-10-07 06:30 UTC] latestfashionind at gmail dot com
The auspicious event includes women-only ceremonies in the evening, where the ladies are dressed to the nines, their hands decked with the latest https://www.stylegods.com/karwa-chauth-mehndi-designs/, and all their outfits pretty much bridal. In other words, the only difference between them and an actual bride is the fact that the former has already been brides.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 00:01:27 2019 UTC