PHP money_format() Function

PHP money_format() Function

The money_format() function in PHP formats a number as a currency string and returns a formatted version of number.

Syntax

money_format ( string $format , float $number ) 

Parameter

format(required)- This parameter specifies the string to be formatted and how to format the variables in it.

number (required)- This parameter signifies the number to be inserted at the %-sign in the format string.

Return

This function returns the formatted string. It returns NULL and emits E_WARNING for Non-numeric number causes.

Example 1

   

Output

Number:4678.76
After using the money_format() function:4678.76   

Example 2

<?php  
//specifying the number
$num =-4678.76;// passing a negative number 
//printing the number
echo "Number:".$num;  
echo "\n";   
//returning a string formatted as a currency string.
setlocale(LC_MONETARY,"de_DE");  
echo "After using the money_format() function:".money_format("%.2n", $num);  
?>   

Output

Number:-4678.76
After using the money_format() function:-4678.76   

Example 3

<?php  
//specifying the number
$num =-4678.76;// passing a negative number 
//printing the number
echo "Number:".$num;  
echo "\n";   
//returning a string formatted as a currency string.
setlocale(LC_MONETARY, 'en_US');  
// Printing the international format as per the en_US locale  
echo "After the money_format() function:".money_format('%i', $num);  
?>   

Output

Number:-4678.76 After the money_format() function:-4678.76 

Related Topics

PHP htmlentities() Function

PHP htmlentities() Function The htmlentities() function in PHP converts all characters to HTML entities. Syntax htmlentities(string,flags,character-set,double_encode);   Parameter string(required)- This parameter specifies the string to convert. flags(optional)- This parameter specifies how to handle quotes, invalid encoding and the used document type. The...

1 minute read.

PHP trim() Function

PHP trim() Function The trim() Function in PHP strips the whitespace or other characters from the beginning and the end of the given string. The trim() function strips the following characters: " " - an ordinary space."\t"- a tab."\n"- a new...

1 minute read.

WordPress Theme

Writing our WordPress Theme is relatively simple. Requirements: Before we begin, we need to know about the following set of requirements. We need to have full knowledge of WordPress setup, which is either...

2 minutes read.

PHP break

What is Break in PHP? Inside the loop, the break statement is used to control the loop in preprocessor hypertext. PHP utilizes the break keyword to implement the break statement, which...

3 minutes read.

PHP array_walk_recursive() Function

PHP array_walk_recursive() Function The array_walk_recursive () function in PHP is used to apply a user-defined callback function recursively to each element of the array. This function returns a Boolean TRUE on success or FALSE on failure. Syntax array_walk_recursive ( array &$array , callable $callback [, mixed $userdata = NULL ] ) Parameter array(required)- This array represents the...

1 minute read.

PHP echo() Function

PHP echo() Function The echo() function in PHP outputs or displays one or more strings. The major differences between print() function and echo() function is that echo accepts an argument list and doesn't have a return value. Also, it is slightly...

1 minute read.

PHP array_combine() Function

PHP array_combine() Function The array_combine() function in PHP is used to create an array by combining two arrays i.e., one array for keys and another array for its values. Syntax array_combine ( array $keys , array $values ) Parameter keys(required)- This parameter represents an array which acts...

1 minute read.

PHP sort() Function

PHP sort() Function The sort() function in PHP sorts an array where the elements will be arranged from lowest to highest. Syntax sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )  Parameter array(required)- This parameter represents the input array. sort_flags (optional)- This parameter is used to modify the...

1 minute read.

PHP vsprintf() Function

PHP vsprintf() Function The vsprintf() function in PHP returns a formatted string. This function accepts an array of arguments. Syntax vsprintf ( string $format , array $args ) Parameter format(required)- This parameter specifies the string and how to format the variables in it. The conversion specification of this parameter...

3 minutes read.

PHP array_uintersect_assoc() Function

PHP array_uintersect_assoc() Function The array_uintersect_uassoc() function in PHP calculates the intersection of arrays by comparing the data and indexes by separate callback functions. It returns an array containing all the values of the first input...

2 minutes read.

PHP Continue

What is continue in PHP? Inside the loop, the continue statement is used to control the loop in preprocessor hypertext. PHP utilizes the continue keyword to implement the continue statement, which...

3 minutes read.

PHP substr_compare() Function

PHP substr_compare() Function The substr_compare() function in PHP compares two strings from a specified start position. It is a binary-safe and optionally case-sensitive function. Syntax substr_compare ( string $main_str , string $str , int $offset [, int $length [, bool$case_insensitivity]] )  Parameter main_str(required)- This parameter specifies the first string to compare. str(required)- This parameter...

1 minute read.

PHP array_intersect_ukey() function

The array_intersect_ukey () function in PHP is used to compute the intersection of arrays with the help of a callable function on the keys for comparison. It returns an array containing all the...

1 minute read.

PHP intval() Function

The intval() Function in PHP is used to get the integer value for the given variable. This function should not be used on objects. Else it will emit an E_NOTICE level error and return 1. Syntax intval...

1 minute read.

PHP shuffle() Function

PHP shuffle() Function The shuffle() function in PHP shuffles an array in a random array. Syntax shuffle ( array &$array )  Parameter array(required)- This parameter represents the input array.  Return This parameter returns a Boolean value TRUE on success or FALSE on failure. Example 1 Output Original Array: Array ...

1 minute read.

PHP current() function

PHP current() function The current() function in PHP returns the current element in an array, which is initialized to the first element inserted into the array. Syntax current ( array $array )   Parameter array (required)– This parameter represents the input array or countable object. Return This...

1 minute read.

PHP array_merge() Function

PHP array_merge() Function The array_merger() Function in PHP merges the elements of one or more arrays wherein the values of one are appended to the end of the previous one. It returns the resulting array...

1 minute read.

PHP Switch Statement with Example

PHP switch statement The PHP switch statement is used to execute one condition from many conditions.It similar to if statements on the same expression. Syntax: switch(n) {             case1: statement if n=case1; break;             case2:             statement if n=case2; break;             case3:            ...

3 minutes read.

PHP array_fill() function

PHP array_fill() function The array_fill() function in PHP fills an user-defined array with num entries of the value that of specified values parameter, where the keys start at the start_index parameter. Syntax array_fill ( int $start_index , int $num , mixed $value ) Parameter start_index(required)- This parameter represents the first index of the...

1 minute read.

PHP strtr() Function

PHP strtr() Function The strtr() function in PHP translates or replaces certain characters in a string. Syntax strtr ( string $str , string $from , string $to ) or strtr ( string $str , array $replace_pairs ) Parameter str(required)- This parameter specifies the string to translate from(required)- This parameter represents the string being translated to the parameter ‘to’. to(required)- It specifies what...

1 minute read.