ricardokovalski / money-formatter
Biblioteca para formatar valores monetários.
v1.0.2
2021-08-05 00:52 UTC
Requires
- php: >=5.6
- ext-intl: *
- ext-json: *
- moneyphp/money: ^3.3
- ricardokovalski/locale: v1.0.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-11-05 08:12:08 UTC
README
Uma biblioteca PHP para formatar valores monetários.
Sobre
ricardokovalski/money-formatter é uma biblioteca PHP que serve para formatar valores monetários.
Instalação
Instale este pacote como uma dependência usando Composer.
composer require ricardokovalski/money-formatter
Uso
BaseFormatterConfig
use RicardoKovalski\MoneyFormatter\Enums\IsoCodes; use RicardoKovalski\MoneyFormatter\Enums\Locale; use RicardoKovalski\MoneyFormatter\Formatters\BaseFormatterConfig; $formatterConfig = new BaseFormatterConfig(IsoCodes::BRL, Locale::PT_BR);
Opções
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);
DecimalFormatter
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
IntlDecimalFormatter
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
IntlCurrencyFormatter
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
Copyright and License
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.