Immutable arbitrary-precision Money and Currency value objects for Laravel: ISO 4217 + custom currencies, exact decimal parsing, rounding-safe arithmetic and allocation, locale formatting, Eloquent casts and schema macros, validation, discounts, tax, and pluggable exchange rates (array, database, ECB).
roundly-consulting/money-for-laravel is a Laravel package for immutable arbitrary-precision money and currency value objects for laravel: iso 4217 + custom currencies, exact decimal parsing, rounding-safe arithmetic and allocation, locale formatting, eloquent casts and schema macros, validation, discounts, tax, and pluggable exchange rates (array, database, ecb)..
It currently has 5 GitHub stars and 619 downloads on Packagist (latest version 1.0.3).
Install it with composer require roundly-consulting/money-for-laravel.
Discover more Laravel packages by roundly-consulting
or browse all Laravel packages to compare alternatives.
Last updated
Immutable, arbitrary-precision Money and Currency value objects for Laravel: exact decimal
parsing, rounding-safe arithmetic and allocation, locale formatting, Eloquent casts, validation,
discounts, tax and pluggable exchange rates. Amounts are minor units held as integer strings with
bcmath arithmetic, so there is no float anywhere and no int64 ceiling.
Requires PHP 8.4 (ext-bcmath; ext-intl for locale-aware formatting) and Laravel 12 or 13.
composer require roundly-consulting/money-for-laravel
Calculate with exact amounts. Every lossy step rounds once, and currencies never mix silently:
use RoundlyConsulting\Money\Money;
$price = Money::ofMajor('19.99', 'EUR'); // minor "1999", never a float
$total = $price->add(Money::ofMinor(250, 'EUR'))->multiply(3); // 67.47 EUR, exact
[$a, $b, $c] = $total->allocate(1, 1, 1); // parts always sum back to $total
$total->add(Money::ofMajor('1', 'USD')); // throws CurrencyMismatch
$total->toDecimal(); // "67.47"
$total->format('sk'); // "67,47 €"
Store it on a model: $table->money('price') creates the amount and currency columns:
use RoundlyConsulting\Money\Casts\AsMoney;
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->money('price'); // decimal(38,0) price + price_currency
$table->timestamps();
});
final class Product extends Model
{
protected $fillable = ['price'];
protected function casts(): array
{
return ['price' => AsMoney::class];
}
}
$product = Product::create(['price' => Money::ofMajor('19.99', 'EUR')]);
Convert with the Exchange facade (ECB rates by default, no setup):
use RoundlyConsulting\Money\Facades\Exchange;
$product->price->convertTo('USD'); // Money in USD at today's rate
Exchange::convertWithRate($product->price, 'CZK'); // Conversion: original, converted, rate
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/money-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
The MIT License (MIT). See LICENSE.md.