Computer >> Computer tutorials >  >> Programming >> PHP

money_format() function in PHP


The money_format() function formats a number as a currency string. It returns the formatted strings or NULL on failure.

Syntax

money_format ( format , number )

Parameters

  • format − It contains the information about specified string to be formatted.

  • number − The number to be inserted at the %-sign in the format string.

Return

The money_format() function returns the formatted strings or NULL on failure.

Example

The following is an example −

<?php
   $input = 1000.56; 
   setlocale(LC_MONETARY,"de_DE"); 
   echo money_format("%.2n", $input);
?>

Output

1000.56

Example

The following is an example −

<?php
   $number = 3825.91;
   setlocale(LC_MONETARY, 'it_IT');
   echo money_format('%.2n', $number) . "\n";
?>

Output

3825.91