moneyphp / money

PHP implementation of Fowler's Money pattern.
http://moneyphp.org
MIT License
4.6k stars 440 forks source link

Round function not working #680

Closed pmoore95 closed 2 years ago

pmoore95 commented 2 years ago

Constructor only accepts integer(ish) values e.g.

$15.25 is represented with:

$price = new \Money\Money('1525', new Currency('USD'));

However the round function does not work:

$price->multiply(1 , Money::ROUND_UP);

returns '1525'

As it is considered an integer in all the round functions such as ceil() :

public function ceil($number)
    {
        $number = Number::fromNumber($number);

        if ($number->isInteger()) {
            return (string) $number;
        }

        if ($number->isNegative()) {
            return bcadd((string) $number, '0', 0);
        }

        return bcadd((string) $number, '1', 0);
    }
And just returns the same string.

This function works if the parameter is "15.25" but this isn't allowed in the constructor.
pmoore95 commented 2 years ago

Never mind, this isn't an issue apologies.