Re: [PHP] newbie question

From: Eugene Lee (list-php-1_at_fsck.net)
Date: 10/13/03


Date: Sun, 12 Oct 2003 17:36:28 -0500
To: PHP-General <php-general@lists.php.net>

On Mon, Oct 13, 2003 at 03:23:53AM +1000, Wang Feng wrote:
:
: "1. 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. An alternate
: padding character can be specified by prefixing it with a single quote (').
: See the examples below."
: "3. An optional number, a width specifier that says how many characters
: (minimum) this conversion should result in."
: ---- http://au.php.net/manual/en/function.sprintf.php
:
: Assume that $price=.65; then the "%0.2f" yields 0.65.
:
: If we follow what the manual says, then can you tell me what the 0 is used
: for? Is it a (optional) paddinng spcifier OR is it a (optional) width
: specifier OR both? And why does it yiled 0.65 rather than .65?
:
: (The manual doesn't explain things clear, man.)

The PHP manual is vague in several sections. I wonder how bug reports
get submitted for it?

The optional specifiers to the left of the decimal place have a psuedo
last-to-first precedence. For example:

        $price = .65;

        printf("'%8.2f'\n", $price);
        -> ' 0.65'

This shows that there are 8 characters reserved for the number to the
left of the decimal. Therefore, '8' is the width specifier.

        printf("'%-8.2f'\n", $price);
        -> '0.65 '

        printf("'%08.2f'\n", $price);
        -> '00000000.65'

        printf("'%0-8.2f'\n", $price);
        -> '0.650000000'



Relevant Pages

  • Re: [PHP] newbie question
    ... padding the results to the right string size. ... This may be a space character ... a width specifier that says how many characters ...
    (php.general)
  • Re: reading variably sized floats
    ... It's supposed to be the f5.2 specifier. ... In the input file the line being read is: ... The tab character is just a character and is counted as 1 when using ... Most COMPILERS will adjust for the tab character in the SOURCE ...
    (comp.lang.fortran)
  • Re: question on character-like variable defination
    ... In a character declaration, the length of the strings is specified ... type name itself or as a specifier on each variable being declared. ...
    (comp.lang.fortran)
  • Re: question on character-like variable defination
    ... James Giles wrote: ... type name itself or as a specifier on each variable being declared. ... The default length is one character. ... obsolescent. ...
    (comp.lang.fortran)
  • Re: Java: Cramer-Shoup 98 Crypto System
    ... > I have not been following the discussion on good padding in this group. ... > block padding is shorter than your TERMINATOR string. ... > that earlier Java dialects on Unix/Linux just treat this bit as part ... > of the character, others read the whole character as ...
    (sci.crypt)