Συνάρτηση money_format() του PHP
Παράδειγμα
Περιγραφή της ενότητας en_US:
<?php $number = 1234.56; setlocale(LC_MONETARY,"en_US"); echo money_format("The price is %i", $number); ?>
The output of the above code:
The price is USD 1,234.56
Ορισμός και χρήση
Η συνάρτηση money_format() επιστρέφει τη συμβολοσειρά που έχει μορφοποιηθεί ως νόμισμα.
Η συνάρτηση αυτή εισάγει έναν μορφοποιημένο αριθμό στη θέση του τομέα τομέα (%) του κύριου συμβολοσειράς.
Note:Η συνάρτηση money_format() δεν μπορεί να λειτουργήσει στο Windows.
Συμβουλές:Αυτός ο συνάρτηση συχνά χρησιμοποιείται με setlocale() χρησιμοποιούνται μαζί.
Συμβουλές:Για να δείτε όλους τους διαθέσιμους κώδικες γλώσσας, παρακαλώ επισκεφθείτε τοΠαρατηρήσεις κώδικα γλώσσας。
Γραμματική
money_format(string,number)
Παράμετροι | Περιγραφή |
---|---|
string |
Απαιτείται. Ορίζει τη συμβολοσειρά που πρέπει να μορφοποιηθεί και πώς θα μορφοποιηθούν οι μεταβλητές της. Πιθανές τιμές μορφοποίησης: Συμπληρωματικοί χαρακτήρες και σημεία στίξης:
Πλάτος πεδίου:
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 to be inserted into the position of the % symbol in the formatted string. |
Technical Details
Return value: |
Returns the formatted string. Characters before and after the formatted string will remain unchanged. Non-numeric numbers 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 the negative sign of the US international format, right precision of 2, and "*" as the fill character:
<?php $number = -1234.5672; echo money_format("%=*(#10.2n",$number); ?>
The output of the above code:
(******1234.57)