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

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

azathoth/money-math
===================

gmp-based arbitrary precision operations on currency amounts "XXX.YY"; because floats are BAD for representing money

0.1.4(11y ago)1151MITPHPPHP &gt;=5.4.0

Since Sep 21Pushed 11y ago2 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (6)Used By (1)

[![Build Status](https://camo.githubusercontent.com/df51be693d545fd9f63b0de0241cb0c26680e2e3f20f1f153e736d9899ab8ea7/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f696b722f6d6f6e65792d6d6174682d7068702e706e67)](http://travis-ci.org/ikr/money-math-php)

What does it do?
================

[](#what-does-it-do)

Arithmetic operations on currency amounts. Amounts on input and output are arbitrary large and precise:

```
99999999999999999999999999999999999999999999999999999999999999999999999999999999.99
+
0.01
=
100000000000000000000000000000000000000000000000000000000000000000000000000000000.00

```

However, in cases when the division is involved — like for percentage calculation — the result is rounded to the whole cent: 33% of $0.50 is $0.17 instead of $0.165

As a bonus feature, there's a simple formatting function for amounts in CHF, EUR, USD, GBP, and JPY.

Why does it exist?
==================

[](#why-does-it-exist)

Because storing currency amounts in floats [is a really bad idea](http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency)

How to use it?
==============

[](#how-to-use-it)

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

[](#installation)

Install via [Composer package manager](http://packagist.org):

Just create a `composer.json` file for your project:

```
{
    "require": {
        "ikr/money-math": "0.1.*"
    }
}

```

And run these two commands to install the Composer dependencies:

```
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

```

Now you can add the Composer's autoloader, and you will have access to the `MoneyMath\*` classes:

```
