コード例 #1
0
ファイル: MoneySpec.php プロジェクト: assimtech/money
 function let(Currency $currency)
 {
     Locale::setDefault('en-US');
     $currency->__toString()->willReturn('USD');
     $currency->getFractionDigits()->willReturn(2);
     $this->beConstructedWith(1.234, $currency);
 }
コード例 #2
0
ファイル: Money.php プロジェクト: assimtech/money
 /**
  * @param string|null $locale if null, defaults to Locale::getDefault
  * @return string
  */
 public function getFormattedAmount($locale = null)
 {
     if ($locale === null) {
         $locale = Locale::getDefault();
     }
     $numberFormatter = new NumberFormatter($locale, NumberFormatter::DECIMAL);
     $fractionDigits = $this->currency->getFractionDigits();
     $numberFormatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $fractionDigits);
     $numberFormatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $fractionDigits);
     return $numberFormatter->format($this->amount);
 }