You are here: Re: printf() « All PHP « IT news, forums, messages
Re: printf()

Posted by J.O. Aho on 09/27/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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация