moneyphp / money

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

Enhancement:: Allow multiply by float numbers less than 1 #791

Closed TAGHREEDAA closed 1 month ago

TAGHREEDAA commented 1 month ago

I got an issue while trying to multiply by float multiplier less than 1 values

example: $price = (new Money(4320, new Currency('SAR')))->multiply(0.78)->multiply(2); this gives zero result because 0.78is not a string

I suggest to modify the multiply function here

public function multiply(float|string $multiplier, int $roundingMode = self::ROUND_HALF_UP): Money
    {
        if (is_int($multiplier) || is_float($multiplier)) {
            $multiplier = (string) $multiplier;
        }

        $product = $this->round(self::$calculator::multiply($this->amount, $multiplier), $roundingMode);

        return new self($product, $this->currency);
    }
begench993 commented 1 month ago

No float :), it has been explained before