/** * money * * @param float|\browner12\money\Money $money * @param string $currency * @return string */ function money($money, $currency = 'usd') { //money object if ($money instanceof \browner12\money\Money) { $currency = $money->getCurrency()->currency(); $money = $money->value(); } //formatter $cf = new NumberFormatter('eng', NumberFormatter::CURRENCY); //return return $cf->formatCurrency($money, $currency); }
/** * compare * * tell user if $money1 is less than (-1), greater than (1), or equal to (0) $money2 * * @param \browner12\money\Money $money1 * @param \browner12\money\Money $money2 * @return int */ public function compare(Money $money1, Money $money2) { //check currencies $this->isSameCurrency([$money1, $money2]); //equal to if ($money1->subunits() == $money2->subunits()) { return 0; } //greater than or less than return $money1->subunits() > $money2->subunits() ? 1 : -1; }