PHP -zelfstudie

PHP HOME PHP-intro PHP-installatie PHP-syntaxis PHP-opmerkingen PHP-variabelen PHP-echo / afdrukken PHP-gegevenstypen PHP-strings PHP-nummers PHP-wiskunde PHP-constanten PHP-operators PHP Als...Anders...Anders PHP-switch PHP-loops PHP-functies PHP-arrays PHP Superglobals PHP RegEx

PHP- formulieren

PHP-formulierverwerking PHP-formuliervalidatie PHP-formulier vereist URL/e-mail van PHP-formulier PHP-formulier voltooid

PHP Geavanceerd

PHP-datum en tijd PHP opnemen PHP-bestandsverwerking PHP-bestand openen/lezen PHP-bestand maken/schrijven PHP-bestand uploaden PHP-cookies PHP-sessies PHP-filters PHP-filters geavanceerd PHP-callback-functies PHP JSON PHP-uitzonderingen

PHP OOP

PHP Wat is OOP PHP-klassen/objecten PHP-constructor PHP-vernietiger PHP-toegangsmodificaties PHP-overerving PHP-constanten PHP abstracte lessen PHP-interfaces PHP-kenmerken PHP statische methoden Statische eigenschappen van PHP PHP-naamruimten PHP-iterables

MySQL- database

MySQL-database MySQL Connect MySQL DB maken MySQL-tabel maken MySQL Gegevens invoegen MySQL Laatste ID ophalen MySQL Meerdere invoegen MySQL voorbereid MySQL Gegevens selecteren MySQL Waar MySQL Bestel op MySQL Gegevens verwijderen MySQL-updategegevens MySQL-limietgegevens

PHP XML

PHP XML-parsers PHP SimpleXML-parser PHP SimpleXML - Get PHP XML Expat PHP XML DOM

PHP - AJAX

Ajax-intro AJAX PHP AJAX-database AJAX XML Live zoeken in Ajax Ajax-peiling

PHP- voorbeelden

PHP-voorbeelden PHP-compiler PHP-quiz PHP-oefeningen PHP-certificaat

PHP- referentie

PHP-overzicht PHP-array PHP-agenda PHP-datum PHP-map PHP-fout PHP-uitzondering PHP-bestandssysteem PHP-filter PHP FTP PHP JSON PHP-sleutelwoorden PHP Libxml PHP-e-mail PHP-wiskunde PHP Diversen PHP MySQLi PHP-netwerk PHP-uitvoercontrole PHP RegEx PHP SimpleXML PHP-stream PHP-string Beheer van PHP-variabelen PHP XML-parser PHP-zip PHP-tijdzones

PHP money_format() Functie

❮ Referentie voor PHP-tekenreeksen

Voorbeeld

Internationaal en_US formaat:

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

De uitvoer van de bovenstaande code zal zijn:

The price is USD 1,234.56


Definitie en gebruik

De functie money_format() retourneert een tekenreeks die is opgemaakt als een valutatekenreeks.

Deze functie voegt een opgemaakt getal in met een procentteken (%) in de hoofdtekenreeks.

Opmerking: de functie money_format() werkt niet op Windows-platforms.

Tip: Deze functie wordt vaak samen met de functie setlocale() gebruikt.

Tip: Ga naar onze Taalcodereferentie om alle beschikbare taalcodes te bekijken.


Syntaxis

money_format(string,number)

Parameterwaarden

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


Technische details

Winstwaarde: Retourneert de opgemaakte tekenreeks. Tekens voor en na de opmaakreeks worden ongewijzigd geretourneerd. Niet-numeriek getal zorgt ervoor dat NULL wordt geretourneerd en E_WARNING wordt uitgezonden
PHP-versie: 4.3.0+

Meer voorbeelden

Voorbeeld

Internationaal formaat (Duitsland) met 2 decimalen:

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

De uitvoer van de bovenstaande code zal zijn:

1 234,56 EUR

Voorbeeld

Negatief getal, Amerikaans nationaal formaat met () om negatieve getallen en 2 cijfers van juiste precisie aan te geven en "*" als opvulteken:

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

De uitvoer van de bovenstaande code zal zijn:

(******1234.57)


❮ Referentie voor PHP-tekenreeksen