https://github.com/krakphp/money
Money manipulation library
https://github.com/krakphp/money
Last synced: about 1 year ago
JSON representation
Money manipulation library
- Host: GitHub
- URL: https://github.com/krakphp/money
- Owner: krakphp
- License: mit
- Created: 2016-04-25T22:39:28.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-26T09:15:35.000Z (almost 9 years ago)
- Last Synced: 2025-01-29T06:52:19.754Z (over 1 year ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Money
Simple money manipulation library which uses bcmath to manipulate money values appropriately.
## Install
Install via composer at `krak/money`
## Usage
```php
add('1.00', '2.00');
$res = $calc->mul($res, 2);
```
## API
### calc($precision = 2)
Returns a cached instance of the BCMathCalculator. Set the precision to higher if you need to do any multiplications or divisions
with the money that might require extra precision.
### preciseCalc()
Returns a cached instance of the FloatCalculator. Use this calculator if you have to do any intense money calculations like calculate compounding interest where you need a LOT of precision. Once done, you should then use the `money\f` to format the resulting money as proper money.
### f($money)
Format the money by rounding it to two decimal places and returning a properly formatted money string of `\d+\.\d{2}`
### interface Calculator
```php
0 if `$a` is > `$b` and < 0 else.
### abstract class AbstractCalculator
```php
$b */
public function gt($a, $b);
/** returns true if $a >= $b */
public function gte($a, $b);
/** returns true if $a == $b */
public function eq($a, $b);
/** returns true if $a != $b */
public function neq($a, $b);
abstract public function add($a, $b);
abstract public function sub($a, $b);
abstract public function mul($a, $b);
abstract public function div($a, $b);
abstract public function cmp($a, $b);
}
```
Any calculator should extend this class instead of directly implementing the `Calculator` interface so that it can have these extra methods.
Each method simply will find the sum, difference, quotient, product, max, or min of the set of args. They delegate the actual calculations to the abstract functions.
## Tests
```
make test
```