Exemplo n.º 1
0
 /**
  * @param self|int|string|float $arg
  * @throws InvalidArgumentException
  * @return int|float
  */
 protected function valueToNumber($arg)
 {
     if ($arg instanceof self) {
         return $arg->toInt();
     }
     return Math::parseNumber($arg);
 }
Exemplo n.º 2
0
 /**
  * @param float|int|string amount in currency main unit (fraction part is in subunit)
  * @param Currency
  * @return Money
  */
 public static function fromFloat($amount, Currency $currency = NULL)
 {
     $currency = $currency ?: new NullCurrency();
     $amount = round(Math::parseNumber($amount) * $currency->getSubunitsInUnit());
     return new static($amount, $currency);
 }