Re: newbie question

From: Date: Sun, 12 Oct 2003 08:57:35 +0000
Subject: Re: newbie question
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-165883@lists.php.net to get a copy of this message
Hi, Eugene, 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 say then? BTW, what's the 1 used for? cheers, feng ----- Original Message ----- From: "Eugene Lee" <list-php-1@fsck.net> To: <php-general@lists.php.net> Sent: Sunday, October 12, 2003 6:49 PM Subject: Re: [PHP] newbie question > On Sun, Oct 12, 2003 at 06:09:21PM +1000, Wang Feng wrote: > : > : This is the example from the php manual: > [...] > : $formatted = sprintf("%01.2f", $money); // my question comes here > : // echo $formatted will output "123.10" > [...] > : > : I don't understand the meaning of the 01 above, which follows the % sign. I > : tried the "%.2f" and "%1.2f", both work fine. So, what's the meaning > of > : 01(especially what the 0 is for)? Seems very much the same as C anyway :-). > > The "01" part guarantees that your money always has a preceding "0" for > decimal-only amounts. For example, ".15" should be displayed as "0.15". > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#165883) next »