/** * 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); }
/** * allocate by ratios * * @todo WIP * @param \browner12\money\Money $money * @param array $ratios * @return array */ public function allocateByRatios(Money $money, $ratios) { //total $total = array_sum($ratios); //loop foreach ($ratios as $ratio) { $allocations[] = $money->subunits() * $ratio / $total; } //make new money objects foreach ($allocations as $allocation) { $return[] = new Money($allocation, $money->getCurrency()->currency()); } //return return $return; }