Uma biblioteca PHP para formatar valores monetários.
ricardokovalski/money-formatter é uma biblioteca PHP que serve para formatar valores monetários.
Instale este pacote como uma dependência usando Composer.
composer require ricardokovalski/money-formatter
use RicardoKovalski\MoneyFormatter\Enums\IsoCodes;
use RicardoKovalski\MoneyFormatter\Enums\Locale;
use RicardoKovalski\MoneyFormatter\Formatters\BaseFormatterConfig;
$formatterConfig = new BaseFormatterConfig(IsoCodes::BRL, Locale::PT_BR);
use RicardoKovalski\MoneyFormatter\Enums\IsoCodes;
use RicardoKovalski\MoneyFormatter\Enums\Locale;
use RicardoKovalski\MoneyFormatter\Formatters\BaseFormatterConfig;
$formatterConfig = new BaseFormatterConfig(IsoCodes::BRL, Locale::PT_BR);
$formatterConfig->resetCurrencyIsoCode(IsoCodes::USD);
$formatterConfig->resetLocale(Locale::EN_US);
$formatterConfig->resetFractionDigits(3);
use RicardoKovalski\MoneyFormatter\Enums\IsoCodes;
use RicardoKovalski\MoneyFormatter\Enums\Locale;
use RicardoKovalski\MoneyFormatter\Formatters\BaseFormatterConfig;
use RicardoKovalski\MoneyFormatter\Formatters\Types\DecimalFormatter;
$formatterConfig = new BaseFormatterConfig(IsoCodes::BRL, Locale::PT_BR);
$decimalFormatter = new DecimalFormatter($formatterConfig);
$decimalFormatter->format(100); //100.00
$decimalFormatter->format(185.45); //185.45
use RicardoKovalski\MoneyFormatter\Enums\IsoCodes;
use RicardoKovalski\MoneyFormatter\Enums\Locale;
use RicardoKovalski\MoneyFormatter\Formatters\BaseFormatterConfig;
use RicardoKovalski\MoneyFormatter\Formatters\Types\IntlDecimalFormatter;
$formatterConfig = new BaseFormatterConfig(IsoCodes::BRL, Locale::PT_BR);
$intlDecimalFormatter = new IntlDecimalFormatter($formatterConfig);
$intlDecimalFormatter->format(500.67); //500,67
$intlDecimalFormatter->format(1945.52); //1.945,52
use RicardoKovalski\MoneyFormatter\Enums\IsoCodes;
use RicardoKovalski\MoneyFormatter\Enums\Locale;
use RicardoKovalski\MoneyFormatter\Formatters\BaseFormatterConfig;
use RicardoKovalski\MoneyFormatter\Formatters\Types\IntlCurrencyFormatter;
$formatterConfig = new BaseFormatterConfig(IsoCodes::BRL, Locale::PT_BR);
$intlCurrencyFormatter = new IntlCurrencyFormatter($formatterConfig);
$intlCurrencyFormatter->format(466); //R$466,00
$intlCurrencyFormatter->format(2500.98); //R$2.500,98
The ricardokovalski/money-formatter library is copyright © Ricardo Kovalski and licensed for use under the terms of the MIT License (MIT). Please see LICENSE for more information.