PHP/Data Type/money format — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 10:03, 26 мая 2010
Formatting currency values
<source lang="html4strict">
<?php $number = 1234.56; setlocale(LC_MONETARY, "en_US"); echo money_format("%i", $number) . "\n"; setlocale(LC_MONETARY, "en_DK"); echo money_format("%.2i", $number) . "\n"; $number = -1234.5672; setlocale(LC_MONETARY, "en_US"); echo money_format("%(#10n", $number) . "\n"; echo money_format("%(#10i", $number) . "\n"; ?>
</source>
Formatting with money_format()
<source lang="html4strict">
<?php $income = 5549.3; $debit = -25.95; $formats = array("%i", // international
"%n", // national "%+n", // + and - "%(n", // () for negative );
setlocale(LC_ALL, "en_US"); foreach ($formats as $format ) {
print "$income @ $format = " . money_format($format,$income) . "\n"; print "$debit @ $format = " . money_format($format,$debit) . "\n";
} ?>
</source>