Current Location: Home> Function Categories> money_format

money_format

Format numbers into currency strings
Name:money_format
Category:String
Programming Language:php
One-line Description:Returns a string formatted as a currency string.

Definition and usage

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 .

Example

Example 1

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

Example 2

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

Example 3

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)
Similar Functions
Popular Articles