|
Posted by J.O. Aho on 10/01/50 11:36
Howard wrote:
> Hello everyone (the PHP beginner is back),
> I've begun to read the O'Reilly book "Learning PHP 5" and came across a
> "rough spot". Actually, I'm just not understanding the explanation on
> printf(). It gave the following example (for those of you who have the
> book, it's on page 22):
>
> $price = 5; $tax = 0.075;
> printf('The dish costs $%.2f' , $price * (1 + $tax));
>
> This prints:
> The dish costs $5.38
>
> I know how to figure out a price after tax, but I'm not sure about the
> $%.2f part. If someone can shed some light on this, I would greatly
> appreciate it.
'f' is for "floatvar" and the '.2' is telling that you want only two decimals.
if you use '$%f' you would have got 5.375
if you use '$%.1f' you would have got 5.4
//Aho
Navigation:
[Reply to this message]
|