Esercitazione PHP

PHP HOME Introduzione a PHP Installazione PHP Sintassi PHP Commenti PHP Variabili PHP PHP Eco/Stampa Tipi di dati PHP Stringhe PHP Numeri PHP PHP matematica Costanti PHP Operatori PHP PHP Se...Altro...Altro Passaggio PHP Ciclo PHP Funzioni PHP Array PHP Superglobali PHP RegEx PHP

Moduli PHP

Gestione dei moduli PHP Convalida del modulo PHP Modulo PHP richiesto URL/e-mail del modulo PHP Modulo PHP completo

PHP avanzato

Data e ora PHP PHP Include Gestione dei file PHP Apri/Leggi file PHP Creazione/scrittura di file PHP Caricamento file PHP Cookie PHP Sessioni PHP Filtri PHP Filtri PHP avanzati Funzioni di callback PHP PHP JSON Eccezioni PHP

PHP OOP

PHP Che cos'è OOP Classi/Oggetti PHP Costruttore PHP PHP distruttore Modificatori di accesso PHP Ereditarietà PHP Costanti PHP Classi astratte PHP Interfacce PHP Tratti PHP Metodi statici PHP Proprietà statiche PHP Spazi dei nomi PHP Iterabili PHP

Database MySQL

Database MySQL MySQL Connect MySQL Crea DB MySQL Crea tabella Dati di inserimento MySQL MySQL Ottieni l'ultimo ID MySQL inserisce più MySQL preparato MySQL Seleziona dati MySQL dove MySQL Ordina per MySQL Elimina dati Dati di aggiornamento MySQL Dati limite MySQL

PHP XML

Parser XML PHP Analizzatore PHP SimpleXML PHP SimpleXML - Ottieni PHP XML espatriato PHP XML DOM

PHP - AJAX

Introduzione all'Ajax AJAX PHP Database AJAX XML AJAX Ricerca in tempo reale AJAX Sondaggio AJAX

Esempi PHP

Esempi PHP compilatore PHP Quiz PHP Esercizi PHP Certificato PHP

Riferimento PHP

Panoramica di PHP matrice PHP Calendario PHP Data PHP Directory PHP Errore PHP Eccezione PHP File system PHP Filtro PHP PHP FTP PHP JSON Parole chiave PHP PHP Libxml Posta PHP PHP matematica PHP Varie PHP MySQLi Rete PHP Controllo dell'output PHP RegEx PHP PHP SimpleXML Flusso PHP Stringa PHP Gestione delle variabili PHP Analizzatore XML PHP Zip PHP Fuso orario PHP

PHP formato_moneta() Funzione

❮ Riferimento alla stringa PHP

Esempio

Formato internazionale en_US:

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

L'output del codice sopra sarà:

The price is USD 1,234.56


Definizione e utilizzo

La funzione money_format() restituisce una stringa formattata come stringa di valuta.

Questa funzione inserisce un numero formattato in cui è presente un segno di percentuale (%) nella stringa principale.

Nota: la funzione money_format() non funziona su piattaforme Windows.

Suggerimento: questa funzione viene spesso utilizzata insieme alla funzione setlocale() .

Suggerimento: per visualizzare tutti i codici lingua disponibili, vai al nostro Riferimento codice lingua.


Sintassi

money_format(string,number)

Valori dei parametri

Parameter Description
string Required. Specifies the string to be formatted and how to format the variables in it.

Possible format values:

Padding and Flags:

  • =f - Specifies the character (f) to be used as padding (Example: %=t this uses "t" as padding). Default is space
  • ^ - Removes the use of grouping characters
  • + or ( - Specifies how to show positive and negative numbers. If "+" is used, the local setting for + and - will be used (usually a sign in front of negative numbers, and nothing in front of positive numbers). If "(" is used, negative numbers are enclosed in parenthesis. Default is "+"
  • ! - Stops the use of currency symbols in the output string
  • - If "-" is used, all fields are left-justified. Default is right-justified

Field width:

  • x - Specifies the minimum field width (x). Default is 0
  • #x - Specifies the maximum number (x) of digits expected to the left of the decimal point. This is used to keep formatted output aligned in the same columns. If the number of digits are bigger than x, this specification is ignored
  • .x - Specifies the maximum number (x) of digits expected to the right of the decimal point. If x is 0, the decimal point and the digits to its right will not be shown. Default is local settings

Conversion characters:

  • i - The number is formatted to international currency format
  • n - The number is formatted to national currency format
  • % - Returns the % character

Note: If multiple format values are used, they must be in the same order as shown above.

Note: This function is affected by local settings.

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


Dettagli tecnici

Valore di ritorno: Restituisce la stringa formattata. I caratteri prima e dopo la stringa di formattazione verranno restituiti invariati. Il numero non numerico provoca la restituzione di NULL e l'emissione di E_WARNING
Versione PHP: 4.3.0+

Altri esempi

Esempio

Formato internazionale (Germania) con 2 decimali:

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

L'output del codice sopra sarà:

1 234,56 EUR

Esempio

Numero negativo, formato nazionale USA con () per indicare numeri negativi e 2 cifre di precisione corretta e "*" come carattere di riempimento:

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

L'output del codice sopra sarà:

(******1234.57)


❮ Riferimento alla stringa PHP