PHPackages                             ulabox/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. ulabox/money

ActiveLibrary

ulabox/money
============

Yet another PHP implementation of the Money value object using BCMath

v2.2.0(5y ago)77238.1k↑11.1%10[1 issues](https://github.com/ulabox/money/issues)MITPHPPHP ^7.1 || ^8.0CI failing

Since Feb 27Pushed 5y ago19 watchersCompare

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

READMEChangelog (4)Dependencies (1)Versions (12)Used By (0)

Money
=====

[](#money)

[![Build Status](https://camo.githubusercontent.com/fb9f2db8a296333a676f809dfa63bde76f11ab8ed2099749c90e53bcff8df575/68747470733a2f2f6170692e7472617669732d63692e6f72672f756c61626f782f6d6f6e65792e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/ulabox/money)

PHP 7.1+ Money library using BCMath, inspired by the works of [Mathias Verraes](https://github.com/mathiasverraes/money) and [Commerce Guys](https://github.com/commerceguys/pricing). Use 1.x series for PHP 5.4+ compatibility.

Motivation
----------

[](#motivation)

Representing monetary values using floats is bad, you can lose precision an get weird results. It's better to use a Money value object that uses integers or BCMath. This library uses the latter.

### Why another Money library? There are already tons out there!

[](#why-another-money-library-there-are-already-tons-out-there)

Yup, but most of them use integers as the internal money representation and that doesn't fit our needs! Using integers is fine in most cases and much more performant, but there are times when you need sub-unit calculations. For example, gas pricing here in Spain is calculated using tenths of an Euro cent or 1.001 €. VAT calculations can also make use of this extra precision an Arbitrary Precision library like BCMath provides. We are an ecommerce and we need that extra precision, especially when calculating discounts.

### Why BCMath and not GMP?

[](#why-bcmath-and-not-gmp)

While the GMP library has better performance, its implementation in PHP lacks decimal arithmetic, it can only deal with integers. There's a [proposal](https://wiki.php.net/rfc/gmp-floating-point) to add the decimal implementation to the PHP extension but that's still a work in progress.

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

[](#installation)

Install the library using [composer](https://getcomposer.org). Just run the following command

```
$ composer require ulabox/money:@stable
```

Usage
-----

[](#usage)

```
