[PHP] money_format()

money_format() (funzione PHP) restituisce, da un numero, una stringa formattata come valuta.

tips&tricks

La funzione non è implementata nei server Windows.

Sintassi

money_format($formato, $numero)
parametro descrizione
$formato Il formato della valuta. Inizia con un simbolo percentuale (%), seguito da uno sei seguenti possibili valori:
=f An equals sign followed by a character to be used as the fill character; defaults to the space character.
^ If present, disables the use of grouping characters (for example, 1000 instead of 1,000) as defined by the locale.
+ If present, positive numbers are prefaced with +.
! If present, the currency symbol is not put in the resulting string.
- If present, all fields are left-justified and padded to the right with the fill character. By default, fields are right-justified and padded to the left with the fill character.
w A number indicating the minimum field width. The resulting number is padded to at least this many characters; the
default is 0.
#n A number sign (#) followed by the maximum number of digits to put on the left side of the decimal.
.p A period (.) followed by the number of digits (p) to put on the right side of the decimal.
i If specified, the number is formatted according to the locale’s international currency format (for example, USD 1,234.56).
n If specified, the number is formatted according to the locale’s local currency format (for example, $1234.56).
% Formats the result as a percentage, inserting a percentage (%) character in the resulting string.
$numero Il numero da processare

Esempi

$number = 1234.56;
setlocale(LC_MONETARY,"it_IT");
echo money_format("%.2n", $number);

/* RISULTATO
EUR 1.234,56
*/

Contenuti correlati

Fonti esterne

funzioni php, php

Related Articles

0 Comment