PHP 7.0+ library to make working with money safer, easier, and fun for Malaysia Ringgit!
"If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- Bill Karwin
In short: You shouldn't represent monetary values by a float. Wherever you need to represent money, use this Money value object.
<?php
use Duit\MYR;
$fiveMyr = MYR::given(500);
$tenMyr = $fiveMyr->add($fiveMyr);
list($part1, $part2, $part3) = $tenMyr->allocate(array(1, 1, 1));
assert($part1->equals(MYR::given(334)));
assert($part2->equals(MYR::given(333)));
assert($part3->equals(MYR::given(333)));
To install through composer, simply put the following in your composer.json
file:
{
"require": {
"jomweb/ringgit": "^0.2"
}
}
And then run composer install
from the terminal.
Above installation can also be simplify by using the following command:
composer require "jomweb/ringgit"
use Duit\MYR;
$money = new MYR(540);
$money = MYR::given(540);
$money = MYR::withoutVat(540);
use Duit\MYR;
$money = MYR::beforeVat(540);
use Duit\MYR;
$money = MYR::afterVat(530);