PHP code example of elriseio / finance-money-bundle

1. Go to this page and download the library: Download elriseio/finance-money-bundle 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/ */

    

elriseio / finance-money-bundle example snippets


return [
    // ...
    Elrise\Finance\Bundle\Money\FinanceMoneyBundle::class => ['all' => true],
];

use Elrise\Finance\Bundle\Money\Money;
use Elrise\Finance\Bundle\Money\Currency\Currency;
use Elrise\Finance\Bundle\Money\Currency\CurrencyRegistry;

$registry = CurrencyRegistry::mutable([
    Currency::iso('USD', '840', null, 'US Dollar'),
    Currency::iso('EUR', '978', null, 'Euro'),
    Currency::crypto('BTC', 8, null, 'Bitcoin'),
    Currency::crypto('ETH', 18, null, 'Ether'),
    Currency::custom('POINTS', 0, null, 'Bonus Points'),
]);
$usd = $registry->get('USD');

$deposit = Money::of('100.00', $usd);
$bonus   = $deposit->multipliedBy('1.10');         // '110.00'
$total   = $deposit->plus($bonus);                  // '110.00 USD'
$fmt     = $total->format('ru_RU');                 // '110.00 USD'

// Cross-currency conversion with metadata (DE-021)
$result = $total->convertWithMetadata(
    'EUR',
    new \DateTimeImmutable(),
    $rateProvider,
);
// $result->to()      === Money(95.85, EUR)
// $result->rate()    === '0.9585'
// $result->source()  === 'ecb' (provider-supplied)
// $result->at()      === DateTimeImmutable(...)

// Cross-currency comparison (DE-020)
$sign = $usdMoney->compare($eurMoney, $rateProvider);
// -1 / 0 / 1