PHP/Data Type/money format

Материал из Web эксперт
Перейти к: навигация, поиск

Formatting currency values

 
<?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";
?>



Formatting with money_format()

 
<?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";
}
?>