PHPackages                             sirix/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sirix/money

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sirix/money
===========

A PHP library for handling monetary values with support for both traditional (fiat) and cryptocurrencies

1.2.0(11mo ago)0462MITPHPPHP ^8.1CI passing

Since Feb 18Pushed 11mo ago1 watchersCompare

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

READMEChangelog (8)Dependencies (6)Versions (9)Used By (2)

Sirix Money
===========

[](#sirix-money)

A PHP library for handling monetary values with support for both traditional (fiat) and cryptocurrencies. Built on top of [brick/money](https://github.com/brick/money) with additional features and safeguards.

Features
--------

[](#features)

- Safe and accurate monetary value handling
- Support for both traditional and cryptocurrency values
- Configurable caching system
- Custom currency registration
- Proper handling of minor currency units (cents, satoshi, etc.)
- Strict type checking and comprehensive error handling

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

[](#requirements)

- PHP 8.1 or higher
- [brick/money](https://github.com/brick/money)
- [psr/cache](https://github.com/php-fig/cache) (for caching support)

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

[](#installation)

Install via Composer:

```
composer require sirix/money
```

Basic Usage
-----------

[](#basic-usage)

### Creating Monetary Values

[](#creating-monetary-values)

```
use Brick\Money\Context\AutoContext;
use Brick\Money\Context\CustomContext;
use Sirix\Money\FiatCurrencyCode;
use Sirix\Money\CryptoCurrencyCode;
use Sirix\Money\SirixMoney;
use Brick\Math\RoundingMode;

// Basic usage with default context and rounding
$amount = SirixMoney::of(10.99, FiatCurrencyCode::Usd);

// Advanced usage with custom context and rounding mode
$amount = SirixMoney::of(
    amount: 10.99,
    currencyCode: FiatCurrencyCode::Usd,
    context: new CustomContext(scale: 5), // Custom context
    rounding: RoundingMode::UP
);

// Create from minor units (cents) with default settings
$cents = SirixMoney::ofMinor(1099, FiatCurrencyCode::Usd);

// Create from minor units with custom context and rounding
$cents = SirixMoney::ofMinor(
    amount: 1099,
    currencyCode: 'USD',
    context: new AutoContext(),
    roundingMode: RoundingMode::DOWN
);

// Check if currency is crypto
$isCrypto = SirixMoney::isCrypto('BTC'); // returns true

// Create a money object with trailing zeros
$money = SirixMoney::of('10.90', CryptoCurrencyCode::Bch);

// Get amount with trailing zeros removed (default behavior)
$withoutZeros = SirixMoney::getAmount($money); // returns "10.9"

// Get amount keeping trailing zeros
$withZeros = SirixMoney::getAmount($money, withoutTrailingZeros: false); // returns "10.90000000"

// Example with more decimal places
$precise = SirixMoney::of('10.50000', CryptoCurrencyCode::Bch);
echo SirixMoney::getAmount($precise); // displays: "10.5"
echo SirixMoney::getAmount($precise, false); // displays: "10.50000000"

// Minor amounts are always returned as full integers
$minorAmount = SirixMoney::getMinorAmount($money); // returns "1050000000"
```

### Currency Registry Configuration

[](#currency-registry-configuration)

```
use Sirix\Money\CurrencyRegistry;
use Brick\Money\Currency;

// Get the registry instance
$registry = CurrencyRegistry::getInstance();

// Configure caching
$registry->setCache($psr6CacheImplementation);
$registry->setCachePrefix('custom_prefix_'); //change cache prefix (if necessary)
$registry->setCacheTtl(7200); //set cache ttl (default: 86400 sec)
// Add custom currency
$customCurrency = new Currency('XYZ', 999, 'Custom Currency', 2);
$registry->addCustomCurrency($customCurrency, true); // true for crypto, false for fiat
```

Error Handling
--------------

[](#error-handling)

The library uses specific exceptions for different error cases:

- `UnknownCurrencyException` - When using an unsupported currency
- `InvalidAmountException` - When providing invalid monetary amounts
- `UnsupportedCurrencyException` - When attempting to use an unsupported currency
- `CacheException` - When cache operations fail
- `SirixMoneyException` - Base exception class for general errors

Features in Detail
------------------

[](#features-in-detail)

### Default Rounding Mode

[](#default-rounding-mode)

The library uses `RoundingMode::HALF_UP` as the default rounding mode. This can be overridden by passing a different rounding mode to the `of()` or `ofMinor()` methods.

### Context Support

[](#context-support)

Both `of()` and `ofMinor()` methods support an optional `Context` parameter, allowing you to specify custom decimal places and other context-specific settings.

### Cache Integration

[](#cache-integration)

The library supports PSR-6 compatible cache implementations:

```
$registry = CurrencyRegistry::getInstance();
$registry->setCache($cachePool);
$registry->setCachePrefix('my_app_');
```

Currency Code Enums and Utilities
=================================

[](#currency-code-enums-and-utilities)

Two enum classes that define standardized currency codes for fiat currencies and cryptocurrencies, plus a utility class for creating currency code enum objects from numeric codes.

Special Naming Conventions
--------------------------

[](#special-naming-conventions)

### Separate Enums for Fiat and Crypto Currencies

[](#separate-enums-for-fiat-and-crypto-currencies)

To handle cases where a cryptocurrency code conflicts with an existing fiat currency code (like MNT, SOS, ERN), we use separate enums:

- `FiatCurrencyCode::Mnt` - The fiat currency Mongolian Tugrik (MNT)
- `CryptoCurrencyCode::Mnt` - The cryptocurrency version of MNT
- `FiatCurrencyCode::Sos` - The fiat currency Somali Shilling (SOS)
- `CryptoCurrencyCode::Sos` - The cryptocurrency version of SOS
- `FiatCurrencyCode::Ern` - The fiat currency Eritrean Nakfa (ERN)
- `CryptoCurrencyCode::Ern` - The cryptocurrency version of ERN

### Numeric Prefix Handling

[](#numeric-prefix-handling)

For cryptocurrency codes that begin with numbers (like `1INCH`), the enum case name uses a descriptive word format instead of the number for PHP compatibility:

- Case name: `OneInch`
- Actual value: `'1INCH'`

This is because PHP enum cases cannot start with a number, so we use a readable word representation while preserving the actual cryptocurrency code value.

### CurrencyCode Utility Class

[](#currencycode-utility-class)

The `CurrencyCode` class provides a utility method for creating currency code enum objects from numeric codes:

```
use Sirix\Money\CurrencyCode;

// Create a FiatCurrencyCode from a numeric code
$usd = CurrencyCode::fromNumericCode(840); // Returns FiatCurrencyCode::Usd

// Create a CryptoCurrencyCode from a numeric code
$btc = CurrencyCode::fromNumericCode(1004); // Returns CryptoCurrencyCode::Btc
```

The class automatically determines whether to create a FiatCurrencyCode or CryptoCurrencyCode based on the numeric code:

- Numeric codes &lt; 1000 are treated as fiat currencies
- Numeric codes &gt;= 1000 are treated as cryptocurrencies

Documentation
-------------

[](#documentation)

For complete information about working with currencies in the Sirix Money library, including how to handle both cryptocurrency and fiat currency values, please refer to the currency code documentation in the docs directory.

Related Resources
-----------------

[](#related-resources)

- [README.md](README.md) - Main library documentation and usage examples
- [FiatCurrencyCode.md](./docs/FiatCurrencyCode.md) - Detailed documentation about fiat currency codes
- [CryptoCurrencyCode.md](./docs/CryptoCurrencyCode.md) - Detailed documentation about cryptocurrency codes
- [CurrencyCode.md](./docs/CurrencyCode.md) - Detailed documentation about the CurrencyCode utility class
- [FullCryptoCurrencyList.md](./docs/FullCryptoCurrencyList.md) - Complete List of Available Cryptocurrency Codes
- [FullFiatCurrencyList.md](./docs/FullFiatCurrencyList.md) - Complete List of Available Fiat Currency Codes

License
-------

[](#license)

MIT License

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance50

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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 ~14 days

Recently: every ~25 days

Total

8

Last Release

352d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ecccf9003c061847e877eeea3bdf1b382f6f9dbb11d33112d6b2740bf0533f9?d=identicon)[sirix777](/maintainers/sirix777)

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[whichbrowser/parser

Useragent sniffing library for PHP

1.8k11.6M50](/packages/whichbrowser-parser)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[csharpru/vault-php

Best Vault client for PHP that you can find

8410.3M4](/packages/csharpru-vault-php)[roave/psr-container-doctrine

Doctrine Factories for PSR-11 Containers

99776.7k19](/packages/roave-psr-container-doctrine)[laminas/laminas-paginator

Paginate collections of data from arbitrary sources

245.7M84](/packages/laminas-laminas-paginator)[spiral/attributes

PHP attributes reader

233.6M45](/packages/spiral-attributes)

PHPackages © 2026

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