1. Go to this page and download the library: Download brick/money library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Brick\Money\Money;
use Brick\Money\Context\CashContext;
$profit = Money::of('987.65', 'CHF', new CashContext(step: 5));
[$a, $b, $c] = $profit->allocate(48, 41, 11); // CHF 474.10, CHF 404.95, CHF 108.60
use Brick\Money\Money;
use Brick\Money\MoneyBag;
$eur = Money::of('12.34', 'EUR');
$jpy = Money::of(123, 'JPY');
$moneyBag = new MoneyBag();
$moneyBag->add($eur);
$moneyBag->add($jpy);
use Brick\Money\CurrencyConverter;
$exchangeRateProvider = ...;
$converter = new CurrencyConverter($exchangeRateProvider); // optionally provide a Context here
$money = Money::of('50', 'USD');
$converter->convert($money, 'EUR', roundingMode: RoundingMode::DOWN);
use Brick\Money\ExchangeRateProvider\ConfigurableProvider;
$provider = new ConfigurableProvider();
$provider->setExchangeRate('EUR', 'USD', '1.0987');
$provider->setExchangeRate('USD', 'EUR', '0.9123');
use Brick\Money\ExchangeRateProvider\PDOProvider;
use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration;
$pdo = new \PDO(...);
$configuration = new PDOProviderConfiguration(
tableName: 'exchange_rates',
exchangeRateColumnName: 'exchange_rate',
sourceCurrencyColumnName: 'source_currency_code',
targetCurrencyColumnName: 'target_currency_code',
);
$provider = new PDOProvider($pdo, $configuration);
use Brick\Money\ExchangeRateProvider\ConfigurableProvider;
use Brick\Money\ExchangeRateProvider\BaseCurrencyProvider;
$provider = new ConfigurableProvider();
$provider->setExchangeRate('EUR', 'USD', '1.1');
$provider->setExchangeRate('EUR', 'GBP', '0.9');
$provider = new BaseCurrencyProvider($provider, 'EUR');
$provider->getExchangeRate('EUR', 'USD'); // 1.1
$provider->getExchangeRate('USD', 'EUR'); // 10/11
$provider->getExchangeRate('GBP', 'USD'); // 11/9
use Brick\Money\Currency;
use Brick\Money\Money;
$bitcoin = new Currency(
'XBT', // currency code
0, // numeric currency code, useful when storing monies in a database; set to 0 if unused
'Bitcoin', // currency name
8 // default scale
);