توابع money_format() در PHP
مثال
فرمت بینالمللی en_US:
<?php $number = 1234.56; setlocale(LC_MONETARY,"en_US"); echo money_format("قیمت USD %i", $number); ?>
The output of the above code:
قیمت USD 1,234.56 است
تعریف و استفاده
توابع money_format() یک رشته است که به عنوان رشته پولی فرمت شده بازمیگردد.
این تابع یک عدد فرمت شده را در موقعیت درصد (%) رشته اصلی قرار میدهد.
Note:توابع money_format() نمیتوانند در سیستم عامل ویندوز کار کنند.
نکته:این تابع معمولاً با 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 inserted into the % symbol position in the formatted string. |
Technical Details
Return value: |
Returns the formatted string. Characters before and after the formatted string will remain unchanged and returned. 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 negative numbers in 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)