Example #1
0
 function let(Currency $currency)
 {
     Locale::setDefault('en-US');
     $currency->__toString()->willReturn('USD');
     $currency->getFractionDigits()->willReturn(2);
     $this->beConstructedWith(1.234, $currency);
 }
Example #2
0
 /**
  * @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);
 }