README.md 1.32 KB
Newer Older
Mathias Verraes's avatar
Mathias Verraes committed
1
Money
Mathias Verraes's avatar
Mathias Verraes committed
2
=====
Mathias Verraes's avatar
Mathias Verraes committed
3

4
[![Build Status](https://api.travis-ci.org/mathiasverraes/money.png?branch=master)](http://travis-ci.org/mathiasverraes/money)
5

Mathias Verraes's avatar
Mathias Verraes committed
6
PHP 5.3+ library to make working with money safer, easier, and fun!
Mathias Verraes's avatar
Mathias Verraes committed
7

Mathias Verraes's avatar
Mathias Verraes committed
8
9
10
> "If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- [Bill Karwin](https://twitter.com/billkarwin/status/347561901460447232)

In short: You shouldn't represent monetary values by a float. Wherever
Mathias Verraes's avatar
readme    
Mathias Verraes committed
11
12
you need to represent money, use this Money value object.

13
14
15
16
17
18
19
20
21
22
23
24
25
```php
<?php

use Money\Money;

$fiveEur = Money::EUR(500);
$tenEur = $fiveEur->add($fiveEur);

list($part1, $part2, $part3) = $tenEur->allocate(array(1, 1, 1));
assert($part1->equals(Money::EUR(334)));
assert($part2->equals(Money::EUR(333)));
assert($part3->equals(Money::EUR(333)));
```
Mathias Verraes's avatar
readme    
Mathias Verraes committed
26

Mathias Verraes's avatar
link    
Mathias Verraes committed
27
The documentation is available at http://money.readthedocs.org
Mathias Verraes's avatar
Mathias Verraes committed
28

29
30
31
32
33
34
35
36

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

Install the library using [composer][1]. Add the following to your `composer.json`:

```json
{
37
38
39
    "require": {
        "mathiasverraes/money": "dev-master"
    },
40
41
42
43
44
45
46
47
48
49
    "minimum-stability": "dev"    
}
```

Now run the `install` command.

```sh
$ composer.phar install
```

50
51
52
53
54
55
56
57
Integration
-----------

See [`MoneyBundle`][2] for [Symfony integration][3].

[1]: http://getcomposer.org/
[2]: https://github.com/pink-tie/MoneyBundle/
[3]: http://symfony.com/