PHPackages                             philiprehberger/php-money - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. philiprehberger/php-money

ActiveLibrary[Database &amp; ORM](/categories/database)

philiprehberger/php-money
=========================

Immutable Money value object with currency support, formatting, arithmetic, and Laravel Eloquent cast

v1.1.1(1mo ago)14[2 PRs](https://github.com/philiprehberger/php-money/pulls)MITPHPPHP ^8.2CI passing

Since Mar 9Pushed 1mo agoCompare

[ Source](https://github.com/philiprehberger/php-money)[ Packagist](https://packagist.org/packages/philiprehberger/php-money)[ Docs](https://github.com/philiprehberger/php-money)[ RSS](/packages/philiprehberger-php-money/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

PHP Money
=========

[](#php-money)

[![Tests](https://github.com/philiprehberger/php-money/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-money/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/a1031bc0fbada1cd58ea2385e783e60f0f42085c086c2f069e72cda0c073338e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d6d6f6e65792e737667)](https://packagist.org/packages/philiprehberger/php-money)[![License](https://camo.githubusercontent.com/50b12c9f8437ca4ee5186ad5ee459ab99be24ac594d03b0a38e739ff88068aa3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d6d6f6e6579)](LICENSE)

Immutable Money value object with currency support, formatting, arithmetic, and Laravel Eloquent cast.

Requirements
------------

[](#requirements)

- PHP 8.2+
- `ext-intl` (for `format()`)
- Laravel 11 or 12 (optional, only for `MoneyCast`)

Installation
------------

[](#installation)

```
composer require philiprehberger/php-money
```

### Laravel

[](#laravel)

The package auto-discovers `MoneyServiceProvider`. No configuration is required.

Usage
-----

[](#usage)

### Creating Money

[](#creating-money)

```
use PhilipRehberger\Money\Money;

// Static currency factories — amount in smallest unit (cents)
$price   = Money::USD(1999);   // $19.99
$tax     = Money::EUR(1500);   // €15.00
$pence   = Money::GBP(999);    // £9.99

// Generic factory
$amount  = Money::of(500, 'CAD');  // CA$5.00

// Zero value
$nothing = Money::zero('USD');

// Parse a formatted string
$parsed  = Money::parse('$29.99', 'USD');  // Money::USD(2999)
$parsed2 = Money::parse('€1,299.00', 'EUR'); // Money::EUR(129900)
```

### Arithmetic

[](#arithmetic)

All arithmetic methods return new `Money` instances and leave the original unchanged.

```
$subtotal = Money::USD(1000);
$tax      = Money::USD(80);
$discount = Money::USD(150);

$total = $subtotal->add($tax)->subtract($discount);
$total->getAmount(); // 930 (= $9.30)
```

### Comparison

[](#comparison)

```
$a = Money::USD(1000);
$b = Money::USD(2000);

$a->equals($b);             // false
$a->lessThan($b);           // true
$a->isZero();               // false
$a->isPositive();           // true
$a->isNegative();           // false
```

### Allocation

[](#allocation)

```
// Split $10.00 three ways
$parts = Money::USD(1000)->allocate([1, 1, 1]);
// [334, 333, 333] — totals exactly 1000
```

### Formatting

[](#formatting)

```
$price = Money::USD(1234567);

$price->format('en_US');  // "$12,345.67"
$price->format('de_DE');  // "12.345,67 $"
$price->format('fr_FR');  // "12 345,67 $US"
```

### Laravel Eloquent Cast

[](#laravel-eloquent-cast)

```
use PhilipRehberger\Money\Laravel\MoneyCast;

class Product extends Model
{
    protected $casts = [
        'price' => MoneyCast::class,
    ];
}

$product->price = Money::USD(2999);
$product->save();
// Stored as: {"amount":2999,"currency":"USD"}
```

API
---

[](#api)

### Money

[](#money)

MethodDescriptionReturns`Money::USD(int $amount)`Create USD instance (and other static currency factories)`Money``Money::of(int $amount, string $currency)`Create instance for any currency code`Money``Money::zero(string $currency)`Create zero-value instance`Money``Money::parse(string $value, string $currency)`Parse a formatted string`Money``->getAmount()`Get amount in smallest unit`int``->getCurrency()`Get Currency instance`Currency``->add(Money $other)`Add two money values`Money``->subtract(Money $other)`Subtract two money values`Money``->multiply(int|float $factor)`Multiply by a factor`Money``->divide(int|float $divisor)`Divide by a divisor`Money``->percentage(int|float $percent)`Calculate a percentage`Money``->allocate(int[] $ratios)`Split proportionally without rounding loss`Money[]``->equals(Money $other)`Check equality`bool``->greaterThan(Money $other)`Greater than comparison`bool``->lessThan(Money $other)`Less than comparison`bool``->greaterThanOrEqual(Money $other)`Greater than or equal comparison`bool``->lessThanOrEqual(Money $other)`Less than or equal comparison`bool``->isZero()`Check if amount is zero`bool``->isPositive()`Check if amount is positive`bool``->isNegative()`Check if amount is negative`bool``->format(string $locale = 'en_US')`Locale-aware formatted string`string``->toArray()`Serialise to array`array`### Exceptions

[](#exceptions)

ExceptionWhen thrown`CurrencyMismatchException`Arithmetic or comparison between different currencies`InvalidAmountException`Division by zero, unparseable string, empty/negative ratios`InvalidArgumentException`Unknown currency code, empty currency code, invalid cast inputDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance89

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

3

Last Release

56d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (11 commits)")

---

Tags

laravelmoneycurrencyValue Objecteloquentcast

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-php-money/health.svg)

```
[![Health](https://phpackages.com/badges/philiprehberger-php-money/health.svg)](https://phpackages.com/packages/philiprehberger-php-money)
```

###  Alternatives

[henzeb/enumhancer

Your framework-agnostic Swiss Army knife for PHP 8.1+ native enums

69287.4k2](/packages/henzeb-enumhancer)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)[rennokki/eloquent-settings

Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.

804.2k](/packages/rennokki-eloquent-settings)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
