money_format
Format numbers into currency strings
money_format()
function returns a string formatted as a currency string.
This function inserts a formatted number at the percent sign (%) position in the main string.
Note: money_format()
function does not work on Windows platforms.
Tip: This function is often used with the setlocale()
function.
Tip: To view all available language codes, please visit our language code reference manual .
en_US International Format:
<?php $number = 1234.56 ; setlocale ( LC_MONETARY , "en_US" ) ; echo money_format ( "The price is %i" , $number ) ; ?>
Output of the above code:
The price is USD 1,234.56
International format with 2 decimals (Germany):
<?php $number = 1234.56 ; setlocale ( LC_MONETARY , "de_DE" ) ; echo money_format ( "%.2n" , $number ) ; ?>
Output of the above code:
1 234,56 EUR
Negative number, US international format with () indicating negative number, with the accuracy on the right of 2, and "*" is padded characters:
<?php $number = - 1234.5672 ; echo money_format ( "%=*(#10.2n" , $number ) ; ?>
Output of the above code:
(******1234.57)