Currencies Update
Currencies Update has brought lots of features related to the Currencies.
README.md
documentation is up-to-date with all of the new features.
Numeric codes!
Numeric codes are here! Now you can get a currency not only by ISO-code (3 letters) but also by numeric code.
However, it is still a string because some currency codes start with 0
at the beginning like 012
.
use PostScripton/Money/Currency;
$usd = Currency::code('840');
$usd = Currency::code('USD');
Currency Lists
First of all, Currency Lists were added and you can choose one of them:
all_currencies
- contains almost all the currencies in the world.popular_currencies
- contains only 35 of the most traded currencies on the marketplace.
If you find an issue with a currency in some of the lists, please, open a new issue on:
https://github.com/PostScripton/laravel-money/issues
In order to choose the list by default, go to config/money.php
and choose one of the two lists.
If you need to select another list run-time in the code:
use PostScripton/Money/Currency;
Currency::setCurrencyList(Currency::LIST_ALL);
More info
Now currency objects have more information about a currency. Here are the new methods:
getFullName()
- returns a full name of a currency, e.g. "United States dollar"getName()
- returns just a name of a currency, e.g. "dollar"getNumCode()
- returns a numeric code, e.g. "840"getSymbol()
- quite complex method because it depends on many situative parameters:
4.1. If a currency has more than one symbol, pass an index as the first parameter to choose one.
4.2. If a currency has one symbol, it is returned.
4.3. If a currency has a display as ISO-code, then ISO-code is returned instead of a symbol.
Display symbol
In this version, you can specify whether you want to have a symbol or ISO-code in money to be displayed.
use PostScripton/Money/Currency;
$usd = Currency::code('USD')->setDisplay(Currency::DISPLAY_CODE);
// Currency::DISPLAY_CODE
// Currency::DISPLAY_SYMBOL
$money = Money::make(1234, $usd);
$money->toString(); // "USD 123.4"
$money->settings->getCurrency()->setPosition(Currency::POS_END);
$money->toString(); // "123.4 USD"