Tutorial PHP

PHP INÍCIO Introdução ao PHP Instalação do PHP Sintaxe PHP Comentários PHP Variáveis ​​PHP PHP Eco/Impressão Tipos de dados PHP Strings PHP Números PHP Matemática PHP Constantes PHP Operadores PHP PHP If...Else...Elseif Chave PHP Loops PHP Funções PHP Matrizes PHP PHP Superglobais PHP RegEx

Formulários PHP

Manipulação de formulários PHP Validação de formulário PHP Formulário PHP obrigatório URL/e-mail do formulário PHP Formulário PHP completo

PHP Avançado

Data e hora do PHP Incluir PHP Manipulação de arquivos PHP Arquivo PHP Abrir/Ler Arquivo PHP Criar/Gravar Upload de arquivo PHP Cookies PHP Sessões PHP Filtros PHP Filtros PHP Avançados Funções de retorno de chamada do PHP PHP JSON Exceções do PHP

PHP OOP

PHP O que é POO Classes/objetos PHP Construtor PHP Destruidor PHP Modificadores de acesso PHP Herança PHP Constantes PHP Classes abstratas PHP Interfaces PHP Características PHP Métodos estáticos PHP Propriedades estáticas do PHP Namespaces PHP Iteráveis ​​PHP

Banco de dados MySQL

Banco de dados MySQL MySQL Connect MySQL Criar banco de dados MySQL Criar Tabela Dados de inserção do MySQL MySQL Obter Último ID MySQL Inserir Múltiplo Preparado para MySQL Dados de seleção do MySQL MySQL Onde MySQL Ordenar por Dados de exclusão do MySQL Dados de atualização do MySQL Dados de limite do MySQL

PHP XML

Analisadores XML PHP Analisador PHP SimpleXML PHP SimpleXML - Obter PHP XML Expatriado PHP XML DOM

PHP - AJAX

Introdução AJAX PHP AJAX Banco de dados AJAX XML AJAX Pesquisa em tempo real AJAX Enquete AJAX

Exemplos PHP

Exemplos PHP Compilador PHP Teste PHP Exercícios PHP Certificado PHP

Referência PHP

Visão geral do PHP Matriz PHP Calendário PHP Data do PHP Diretório PHP Erro PHP Exceção PHP Sistema de arquivos PHP Filtro PHP PHP FTP PHP JSON Palavras-chave PHP PHP Libxml Correio PHP Matemática PHP PHP Diversos PHP MySQLi Rede PHP Controle de saída PHP PHP RegEx PHP SimpleXML Fluxo PHP String PHP Manipulação de variáveis ​​PHP Analisador XML PHP PHP Zip Fusos horários PHP

Função PHP money_format()

❮ Referência de String PHP

Exemplo

Formato internacional en_US:

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

A saída do código acima será:

The price is USD 1,234.56


Definição e uso

A função money_format() retorna uma string formatada como uma string de moeda.

Esta função insere um número formatado onde há um sinal de porcentagem (%) na string principal.

Nota: A função money_format() não funciona em plataformas Windows.

Dica: Esta função é frequentemente usada em conjunto com a função setlocale() .

Dica: para visualizar todos os códigos de idioma disponíveis, acesse nossa Referência de código de idioma.


Sintaxe

money_format(string,number)

Valores de parâmetro

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


Detalhes técnicos

Valor de retorno: Retorna a string formatada. Os caracteres antes e depois da string de formatação serão retornados inalterados. Número não numérico faz retornar NULL e emitir E_WARNING
Versão do PHP: 4.3.0+

Mais exemplos

Exemplo

Formato internacional (Alemanha) com 2 casas decimais:

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

A saída do código acima será:

1 234,56 EUR

Exemplo

Número negativo, formato nacional dos EUA com () para indicar números negativos e 2 dígitos de precisão correta e "*" como caractere de preenchimento:

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

A saída do código acima será:

(******1234.57)


❮ Referência de String PHP