"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.)


cheers,

feng


----- Original Message -----
From: "Robert Cummings" <[EMAIL PROTECTED]>
To: "Wang Feng" <[EMAIL PROTECTED]>
Cc: "Curt Zirzow" <[EMAIL PROTECTED]>; "PHP-General"
<[EMAIL PROTECTED]>
Sent: Monday, October 13, 2003 2:29 AM
Subject: Re: [PHP] newbie question

> I believe the documentation (in at least on of the ?printf() functions
> describes how the implementation follows the C specs. I'm pretty sure
> the ?printf() family of functions were added almost entirely for the
> benefit of C coders :)
>
> Cheers,
> Rob.
>
> >
> >
> > cheers,
> >
> > feng
> >
> >
> >
> > ----- Original Message -----
> > From: "Curt Zirzow" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Monday, October 13, 2003 2:01 AM
> > Subject: Re: [PHP] newbie question
> >
> >
> > > * Thus wrote Eugene Lee ([EMAIL PROTECTED]):
> > > > On Sun, Oct 12, 2003 at 06:57:35PM +1000, Wang Feng wrote:
> > > > :
> > > > : If I get rid of the 0 and tried this:
> > > > :
> > > > : $price=.65;
> > > > : $f_price=sprintf("%1.2f",$price);
> > > > :
> > > > : It displays "0.65" in my Mozilla browser correctly. What do you sa
y
> > then?
> > > >
> > > > I say, "I dunno".  :-)  It seems to follow C's printf(3) conversion
> > > > specification.  If a decimal point is needed for a float, it must
also
> > > > have a digit in front of the decimal point.  This is kind of
annoying if
> > > > I want to print decimal-only values without preceding zeroes.  Maybe
> > > > money_format() is a better solution.
> > >
> > > yep, and even  "%0.2f" yields 0.65
> > >
> > >
> > > Curt
> > > --
> > > "My PHP key is worn out"
> > >
> > >   PHP List stats since 1997:
> > >   http://zirzow.dyndns.org/html/mlists/
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting  |
> | a powerful, scalable system for accessing system services  |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for       |
> | creating re-usable components quickly and easily.          |
> `------------------------------------------------------------'
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to