Home >>PHP String Functions >PHP money_format() Function
PHP money_format() function is used to format a number as a currency string. It inserts a formatted number where there is a percent sign (%) in the given input string. This function returns the formatted string or NULL on failure as the output. This function does not work on Windows platform.
Syntax:-
money_format($format, $number);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter contains the given string to be formatted and how to format the variables in it. |
number | This is a required parameter. This parameter contains the number to be inserted at the %-sign in the given format string. |
Here is an example of money_format() function in PHP:
<html> <body> <?php $price = 979; setlocale(LC_MONETARY,"en_US"); echo money_format("The price is %i", $price); ?> </body> </html>
Here is an another example of money_format() function in PHP:
<html> <body> <?php $price = 893; setlocale(LC_MONETARY,"de_DE"); echo money_format("The price is %.2n", $price); ?> </body> </html>