Example
en_US International format:
<?php $number = 1234.56; setlocale(LC_MONETARY,"en_US"); echo money_format("The price is %i", $number); ?>
The above code will output:
The price is USD 1,234.56
Definition and usage
money_format() function returns formatted A string that is a currency string.
This function inserts a formatted number at the percent sign (%) position of the main string.
Note: The money_format() function does not work on Windows platforms.
Tip: This function is often used together with the setlocale() function.
Tip: To see all available language codes, visit our Language Codes Reference Manual.
Syntax
money_format(string,number)
Parameters | Description |
string | Required. Specifies the string to be formatted and how to format the variables in the string. Possible format values: Padding and flags:
##n - The number is formatted in national currency format
技术细节 返回值: 返回已格式化的字符串。格式化字符串前面和后面的字符将保持不变返回。非数值数字会返回 NULL 并产生 E_WARNING。 PHP 版本: 4.3.0+ 更多实例 实例 1 带 2 个小数的国际格式(德国): <?php $number = 1234.56; setlocale(LC_MONETARY,"de_DE"); echo money_format("%.2n", $number); ?> Copy after login 上面的代码将输出: 1 234,56 EUR Copy after login 实例 2 负数,带有 () 指示负数的 US 国际格式,右侧精度为 2,"*" 为填充字符: <?php $number = -1234.5672; echo money_format("%=*(#10.2n",$number); ?> Copy after login 上面的代码将输出: (******1234.57) Copy after login The above is the detailed content of php returns string function money_format() formatted as currency string. For more information, please follow other related articles on the PHP Chinese website!
Previous article:PHP calculates the key function metaphone() of a string
Next article:php function nl2br() that inserts html newline characters before each line in the string
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|