PHP money_format() function
Mga halimbawa
Internasyonal na format ng en_US:
<?php $number = 1234.56; setlocale(LC_MONETARY,"en_US"); echo money_format("Ang presyo ay %i", $number); ?>
The output of the above code:
Ang presyo ay USD 1,234.56
Definisyon at Paggamit
Ang function na money_format() ay ibibigay ang string na naformat bilang string ng pera.
Ang function na money_format() ay maglalagay ng isang format ng numero sa posisyon ng porsyento (%) sa pangunahing string.
Note:Ang function na money_format() ay hindi gumagana sa Windows platform.
Mga tagubilin:Ang function na ito ay karaniwang magiging magkasama sa setlocale() Ginagamit ang mga function na magkasama.
Mga tagubilin:Kung gusto makita ang lahat ng mga magagamit na kode ng wika, bisitahin ninyo ang amingManwal ng Kode ng Wika。
Gramatika
money_format(string,number)
Parametro | Paglalarawan |
---|---|
string |
Mga kinakailangan. Tukuyin ang string na dapat pormatehan at kung paano pormatehan ang mga variable nito. Posible na halaga ng format: Pampinakalat at simbolo:
Lapad ng larawan:
Conversion Characters:
Note:If multiple format values are used, they must appear in the order above. Note:This function is affected by the local settings. |
number | Required. The number inserted into the position of the % symbol in the formatting string. |
Technical Details
Return value: |
Returns the formatted string. Characters before and after the formatted string will remain unchanged and returned. Non-numeric characters will return NULL and produce an E_WARNING. |
PHP Version: | 4.3.0+ |
More Examples
Example 1
International format with 2 decimal places (Germany):
<?php $number = 1234.56; setlocale(LC_MONETARY,"de_DE"); echo money_format("%.2n", $number); ?>
The output of the above code:
1 234,56 EUR
Example 2
Negative numbers, with parentheses () indicating negative numbers in the US international format, right precision of 2, and "*" as the padding character:
<?php $number = -1234.5672; echo money_format("%=*(#10.2n",$number); ?>
The output of the above code:
(******1234.57)