Home > Backend Development > PHP Problem > How to use php money_format function

How to use php money_format function

藏色散人
Release: 2023-02-22 19:20:01
Original
2875 people have browsed it

php money_format function is used to return a string formatted as a currency string. Its syntax is money_format(string,number). The parameter string is required and refers to the string to be formatted and how to format the variables in it.

How to use php money_format function

How to use the php money_format function?

Definition and Usage

The 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 platform.

Tips: This function is often used together with the setlocale() function.

Tip: To see all available language codes, visit our Language Codes Reference Manual.

Syntax

money_format(string,number)
Copy after login

How to use php money_format function

Return value:

Return formatted characters string.

The characters before and after the format string will be returned unchanged. Non-numeric numbers return NULL and generate E_WARNING.

PHP Version: 4.3.0

Example 1

International format with 2 decimals (Germany):

<?php
$number = 1234.56;
setlocale(LC_MONETARY,"de_DE");
echo money_format("%.2n", $number);
?>
Copy after login

Output of the above code:

1 234,56 EUR
Copy after login

Example 2

Negative numbers, with () indicating the US international format for negative numbers, the right-hand side precision is 2, and "*" is Fill character:

<?php
$number = -1234.5672;
echo money_format("%=*(#10.2n",$number);
?>
Copy after login

Output of the above code:

(******1234.57)
Copy after login

Example 3

en_US International format:

<?php
$number = 1234.56;
setlocale(LC_MONETARY,"en_US");
echo money_format("The price is %i", $number);
?>
Copy after login

Output of the above code:

The price is USD 1,234.56
Copy after login

The above is the detailed content of How to use php money_format function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template