antonienko / money-formatter
Formatter for moneyphp/money library using alcohol/iso4217 for obtaining the number of decimal digits in each currency
Installs: 3 856
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 2
Open Issues: 0
Requires
- php: >=5.4
- ext-intl: 1.1.*
- ext-mbstring: *
- alcohol/iso4217: ~2.0
- mathiasverraes/money: ~3.0@beta
- symfony/yaml: ~2.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-11-09 18:38:14 UTC
README
Class to convert Moneyphp/money objects to the base unit representation of the given currency (float) or to a string representation given a locale, using php's intl extension.
To do so it leverages the info provided by the iso4217 library from Alcohol in order to know the exact number of decimal places that each currency uses.
##Installation ###Composer This library is available in packagist.org, you can add it to your project via Composer.
In the "require" section of your composer.json file:
Always up to date (bleeding edge, API not guaranteed stable)
"antonienko/money-formatter": "dev-master"
Specific minor version, API stability
"antonienko/money-formatter": "2.0.*"
Features
- Convert a Money Object to float value, depending on the number of decimal places used by the currency.
- Convert a Money Object to string, formatted using the provided locale.
- Get the currency symbol of a Money Object, either just the symbol or the full currency symbol (The "just the symbol" option for Canadian Dollar would be '$', but if you are in the USA you would need the "full symbol" option "CA$")
- Get the symbol position for a given locale (right or left position)
##Sample Usage
use antonienko\MoneyFormatter\MoneyFormatter; use Money\Currency; use Money\Money; $some_euros = new Money(300005, new Currency('EUR')); $some_dollars = new Money(300005, new Currency('USD')); $mf = new MoneyFormatter('fr_FR'); $amount = $mf->toFloat($some_euros); //$amount will be (float)3000.05 $french_formatted = $mf->toString($some_euros); //$french_formatted will be '3 000,05 €' $just_symbol = $mf->toSymbol($some_dollars); //$just_symbol would be '$' $full_symbol = $mf->toSymbol($some_dollars, false); //$full_symbol would be '$US' $position = $mf->getSymbolPosition($some_euros); //position would be MoneyFormatter::SYMBOL_POSITION_RIGHT
##License Information Licensed under The MIT License (MIT). See the LICENSE file for more details.