NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Money for Laravel

Multi-currency totals

MoneyBag is an immutable multi-currency accumulator — a wallet or basket that keeps balances in several currencies side by side:

use RoundlyConsulting\Money\MoneyBag;

$bag = MoneyBag::of(Money::ofMajor('10', 'EUR'), Money::ofMajor('12', 'USD'))
    ->add(Money::ofMajor('100', 'CZK'))
    ->subtract(Money::ofMajor('2', 'USD'));

$bag->get('USD');         // 10.00 USD
$bag->get('GBP');         // 0.00 GBP — zero when absent
$bag->currencies();       // [CZK, EUR, USD] — sorted by code
$bag->all();              // list<Money>
$bag->isEmpty();          // false

$bag->total('EUR');                    // converted and summed exactly, rounded once
$bag->total('EUR', now()->subDay());   // with historical rates
  • of() and add() group amounts by currency code; subtract() works the same way.
  • get() returns zero for a currency the bag doesn’t hold.
  • currencies() and all() are sorted by code.
  • isEmpty() — balances that return to zero drop out of the bag.
  • A currency with the same code but a different exponent throws CurrencyMismatch.

Totals without drift

total($in, ?$on, ?$rounding) converts every balance through the bound exchange provider and sums them as one exact rational, rounding once at the end (HalfEven by default) — no per-currency rounding drift. Pass a date to use historical rates.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.