Samouczek PHP

Strona główna PHP Wprowadzenie do PHP Instalacja PHP Składnia PHP Komentarze PHP Zmienne PHP PHP Echo / Drukuj Typy danych PHP Ciągi PHP Liczby PHP Matematyka w PHP Stałe PHP Operatory PHP PHP Jeśli...Inne...Elseif Przełącznik PHP Pętle PHP Funkcje PHP Tablice PHP PHP Superglobals PHP RegEx

Formularze PHP

Obsługa formularzy PHP Walidacja formularzy PHP Wymagany formularz PHP Adres URL/e-mail formularza PHP Formularz PHP kompletny

Zaawansowany PHP

Data i godzina w PHP Uwzględnij PHP Obsługa plików PHP Otwórz/odczytaj plik PHP Tworzenie/zapisywanie plików PHP Przesyłanie plików PHP Pliki cookie PHP Sesje PHP Filtry PHP Zaawansowane filtry PHP Funkcje wywołania zwrotnego PHP PHP JSON Wyjątki PHP

PHP OOP

PHP Co to jest OOP Klasy/obiekty PHP Konstruktor PHP Destruktor PHP Modyfikatory dostępu PHP Dziedziczenie PHP Stałe PHP Klasy abstrakcyjne PHP Interfejsy PHP Cechy PHP Metody statyczne PHP Właściwości statyczne PHP Przestrzenie nazw PHP Iterowalne PHP

Baza danych MySQL

Baza danych MySQL Połączenie MySQL Tworzenie bazy danych MySQL Utwórz tabelę MySQL Wstaw dane MySQL Pobierz ostatni identyfikator MySQL Wstaw wiele MySQL Przygotowano MySQL Wybierz dane MySQL MySQL Gdzie Zamów MySQL według Usuń dane MySQL Dane aktualizacji MySQL Dane limitu MySQL

PHP XML

Parsery PHP XML Parser PHP SimpleXML PHP SimpleXML — Get Rozszerzenie PHP XML PHP XML DOM

PHP - AJAX

Wprowadzenie do AJAX AJAX PHP Baza danych AJAX XML AJAX Wyszukiwanie na żywo AJAX Ankieta AJAX

Przykłady PHP

Przykłady PHP Kompilator PHP Quiz PHP Ćwiczenia PHP Certyfikat PHP

Odniesienie do PHP

Przegląd PHP Tablica PHP Kalendarz PHP Data PHP Katalog PHP Błąd PHP Wyjątek PHP System plików PHP Filtr PHP PHP FTP PHP JSON Słowa kluczowe PHP Biblioteka PHP Poczta PHP Matematyka w PHP Różne PHP PHP MySQLi Sieć PHP Kontrola wyjścia PHP PHP RegEx PHP SimpleXML Strumień PHP ciąg PHP Obsługa zmiennych PHP Parser PHP XML Kod pocztowy PHP Strefy czasowe PHP

PHP money_format() Funkcja

❮ Odniesienie do ciągów PHP

Przykład

Międzynarodowy format en_US:

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

Wynikiem powyższego kodu będzie:

The price is USD 1,234.56


Definicja i użycie

Funkcja money_format() zwraca ciąg znaków sformatowany jako ciąg waluty.

Ta funkcja wstawia sformatowaną liczbę, w której w głównym ciągu znajduje się znak procentu (%).

Uwaga: Funkcja money_format() nie działa na platformach Windows.

Wskazówka: Ta funkcja jest często używana razem z funkcją setlocale() .

Porada: Aby wyświetlić wszystkie dostępne kody języków, przejdź do naszej informacji o kodach języków.


Składnia

money_format(string,number)

Wartości parametrów

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


Szczegóły techniczne

Wartość zwrotu: Zwraca sformatowany ciąg. Znaki przed i po ciągu formatującym zostaną zwrócone bez zmian. Liczba nienumeryczna powoduje zwrócenie wartości NULL i wyświetlenie E_WARNING
Wersja PHP: 4.3.0+

Więcej przykładów

Przykład

Format międzynarodowy (Niemcy) z 2 miejscami po przecinku:

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

Wynikiem powyższego kodu będzie:

1 234,56 EUR

Przykład

Liczba ujemna, format krajowy USA z () do oznaczania liczb ujemnych, 2 cyfry z dokładnością do prawej oraz „*” jako znak wypełnienia:

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

Wynikiem powyższego kodu będzie:

(******1234.57)


❮ Odniesienie do ciągów PHP