Re: sprintf() question
| From: | @ Edwin | Date: | Thu, 29 Aug 2002 16:34:22 +0000 |
| Subject: | Re: sprintf() question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-114521@lists.php.net to get a copy of this message | ||
Experiment a bit and I'm sure you'll find it easy. One example, change this portion
$formatted = sprintf("%01.2f", $money);
to
$formatted = sprintf("%01.3f", $money);
then see how it works...
<?php
$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
echo "This is money: $money";
$formatted = sprintf("%01.3f", $money);
echo "This is formatted: $formatted";
?>
HTH,
- E
I read the manual page on sprintf, but I still don't understand exactly how the format string works. $money1 = 68.75; $money2 = 54.35; $money = $money1 + $money2; // echo $money will output "123.1"; $formatted = sprintf("%01.2f", $money); // echo $formatted will output "123.10" How does that work? What part of the string corresponds to what? Thanks for any and all help!_________________________________________________________________ キャリアアップを目指すあなたのナビゲーター MSN 就職・転職 http://career.msn.co.jp/