当前位置: 首页>>代码示例>>PHP>>正文


PHP NumberFormatter::formatCurrency方法代码示例

本文整理汇总了PHP中NumberFormatter::formatCurrency方法的典型用法代码示例。如果您正苦于以下问题:PHP NumberFormatter::formatCurrency方法的具体用法?PHP NumberFormatter::formatCurrency怎么用?PHP NumberFormatter::formatCurrency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NumberFormatter的用法示例。


在下文中一共展示了NumberFormatter::formatCurrency方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPrice

 /**
  * Get price with currency only if data is not null
  * (if data is null and formatted by formatCurrency(), it will return 0)
  *
  * @param \NumberFormatter $numberFormatter
  * @param array            $price
  *
  * @return string
  */
 protected function getPrice(\NumberFormatter $numberFormatter, array $price)
 {
     if (!isset($price['data'])) {
         return '';
     }
     return $numberFormatter->formatCurrency($price['data'], $price['currency']);
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:16,代码来源:PricesPresenter.php

示例2: render

 /**
  * \copydoc ::Erebot::Styling::VariableInterface::render()
  *
  * \note
  *      If no currency was passed to this class' constructor,
  *      the currency associated with the translator's locale
  *      is used.
  */
 public function render(\Erebot\IntlInterface $translator)
 {
     $locale = $translator->getLocale(\Erebot\IntlInterface::LC_MONETARY);
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $currency = $this->currency !== null ? $this->currency : $formatter->getSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL);
     return (string) $formatter->formatCurrency($this->value, $currency);
 }
开发者ID:erebot,项目名称:styling,代码行数:15,代码来源:CurrencyVariable.php

示例3: format

 /**
  * {@inheritdoc}
  */
 public function format($amount, $currency, $locale = 'en')
 {
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $result = $formatter->formatCurrency($amount / 100, $currency);
     Assert::notSame(false, $result, sprintf('The amount "%s" of type %s cannot be formatted to currency "%s".', $amount, gettype($amount), $currency));
     return $result;
 }
开发者ID:TheMadeleine,项目名称:Sylius,代码行数:10,代码来源:MoneyFormatter.php

示例4: currency

 public function currency($value, $currency = 'USD')
 {
     // use of NumberFormatter from extension package intl
     //
     $formatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
     return $formatter->formatCurrency($value, $currency);
 }
开发者ID:ClintonFong,项目名称:backend-test,代码行数:7,代码来源:Helpers.php

示例5: getPattern

 /**
  * Returns the pattern for this locale.
  *
  * The pattern contains the placeholder "{{ widget }}" where the HTML tag should
  * be inserted
  */
 protected static function getPattern($currency)
 {
     if (!$currency) {
         return '{{ widget }}';
     }
     $locale = \Locale::getDefault();
     if (!isset(self::$patterns[$locale])) {
         self::$patterns[$locale] = array();
     }
     if (!isset(self::$patterns[$locale][$currency])) {
         $format = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
         $pattern = $format->formatCurrency('123', $currency);
         // the spacings between currency symbol and number are ignored, because
         // a single space leads to better readability in combination with input
         // fields
         // the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8)
         preg_match('/^([^\\s\\xc2\\xa0]*)[\\s\\xc2\\xa0]*123(?:[,.]0+)?[\\s\\xc2\\xa0]*([^\\s\\xc2\\xa0]*)$/u', $pattern, $matches);
         if (!empty($matches[1])) {
             self::$patterns[$locale][$currency] = $matches[1] . ' {{ widget }}';
         } elseif (!empty($matches[2])) {
             self::$patterns[$locale][$currency] = '{{ widget }} ' . $matches[2];
         } else {
             self::$patterns[$locale][$currency] = '{{ widget }}';
         }
     }
     return self::$patterns[$locale][$currency];
 }
开发者ID:vadim2404,项目名称:symfony,代码行数:33,代码来源:MoneyType.php

示例6: notify

 public function notify(RequestVerifiedEvent $event)
 {
     $payment = $event->getPayment();
     $status = $event->getStatus()->getValue();
     switch ($status) {
         case GetHumanStatus::STATUS_AUTHORIZED:
         case GetHumanStatus::STATUS_CAPTURED:
         case GetHumanStatus::STATUS_REFUNDED:
             $this->repository->clearCart();
             $type = 'success';
             break;
         case GetHumanStatus::STATUS_CANCELED:
         case GetHumanStatus::STATUS_EXPIRED:
         case GetHumanStatus::STATUS_FAILED:
             $type = 'danger';
             break;
         case GetHumanStatus::STATUS_PENDING:
         case GetHumanStatus::STATUS_SUSPENDED:
             $this->repository->clearCart();
             $type = 'warning';
             break;
         case GetHumanStatus::STATUS_NEW:
         case GetHumanStatus::STATUS_UNKNOWN:
             $this->repository->clearCart();
             $type = 'info';
             break;
         default:
             throw new \RuntimeException('Unknown status ' . $status);
     }
     $formatter = new \NumberFormatter($this->translator->getLocale(), \NumberFormatter::CURRENCY);
     $this->session->getFlashBag()->add($type, $this->translator->trans('flash.payment.' . $type, ['%status%' => $this->translator->trans('meta.status.' . $status), '%amount%' => $formatter->formatCurrency($payment->getTotalAmount() / 100, $payment->getCurrencyCode())]));
 }
开发者ID:igaponov,项目名称:shop,代码行数:32,代码来源:PaymentFlashMessageSubscriber.php

示例7: getPattern

 /**
  * Returns the pattern for this locale
  *
  * The pattern contains the placeholder "{{ widget }}" where the HTML tag should
  * be inserted
  */
 public function getPattern()
 {
     if (!$this->getOption('currency')) {
         return '{{ widget }}';
     }
     if (!isset(self::$patterns[$this->locale])) {
         self::$patterns[$this->locale] = array();
     }
     if (!isset(self::$patterns[$this->locale][$this->getOption('currency')])) {
         $format = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
         $pattern = $format->formatCurrency('123', $this->getOption('currency'));
         // the spacings between currency symbol and number are ignored, because
         // a single space leads to better readability in combination with input
         // fields
         // the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8)
         preg_match('/^([^\\s\\xc2\\xa0]*)[\\s\\xc2\\xa0]*123[,.]00[\\s\\xc2\\xa0]*([^\\s\\xc2\\xa0]*)$/', $pattern, $matches);
         if (!empty($matches[1])) {
             self::$patterns[$this->locale] = $matches[1] . ' {{ widget }}';
         } else {
             if (!empty($matches[2])) {
                 self::$patterns[$this->locale] = '{{ widget }} ' . $matches[2];
             } else {
                 self::$patterns[$this->locale] = '{{ widget }}';
             }
         }
     }
     return self::$patterns[$this->locale];
 }
开发者ID:rosstuck,项目名称:Pok,代码行数:34,代码来源:MoneyField.php

示例8: currency

 /**
  * returns a string with currency formatted accordingly to locale settings
  * @param string $value
  * @param string $decimals
  * @param string $currencyCode
  * @return string
  */
 public static function currency($value, $decimals = 2, $currencyCode = null)
 {
     $app = Application::instance();
     $currencyCode = $currencyCode ?: $app->getConfig('app.settings.currency');
     $nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
     $nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
     return $nf->formatCurrency($value, $currencyCode);
 }
开发者ID:titaphp,项目名称:framework,代码行数:15,代码来源:NumberFormatter.php

示例9: formatI18n

 /**
  * localized format for money with the NumberFormatter class in Currency mode
  * with currency symbol
  * like €1.234,56
  *
  * @param Money $money
  * @param null  $locale
  * @return bool|string
  */
 public function formatI18n(Money $money, $locale = null)
 {
     if ($locale === null) {
         $locale = $this->locale;
     }
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     return $formatter->formatCurrency($money->getConvertedAmount(), $money->getCurrency()->getCurrencyCode());
 }
开发者ID:ivoba,项目名称:money-twig-extension,代码行数:17,代码来源:MoneyFormatter.php

示例10: currencySymbolFunction

 /**
  * @todo This is the easiet way I could see to get a currency from a String such as 'GBP'
  * However it's not a very nice solution. This should probably be updated in the future.
  */
 public function currencySymbolFunction($currency = null, $locale = null)
 {
     $locale = $locale == null ? \Locale::getDefault() : $locale;
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $currency = $currency ?: $this->_defaultCurrency;
     $symbol = substr($formatter->formatCurrency(0, $currency), 0, -4);
     return $symbol;
 }
开发者ID:mothership-ec,项目名称:cog,代码行数:12,代码来源:PriceTwigExtension.php

示例11: format

 /**
  * {@inheritDoc}
  */
 public function format($value, $valueCurrency = null, $decimal = true, $symbol = true)
 {
     $formatter = new \NumberFormatter($this->locale, $symbol ? \NumberFormatter::CURRENCY : \NumberFormatter::PATTERN_DECIMAL);
     $value = $formatter->formatCurrency($value, $valueCurrency);
     if (!$decimal) {
         $value = preg_replace('/[.,]00((?=\\D)|$)/', '', $value);
     }
     if (count($this->cleanCharacters) > 0) {
         $value = str_replace($this->cleanCharacters, '', $value);
     }
     return $value;
 }
开发者ID:coffee-bike,项目名称:LexikCurrencyBundle,代码行数:15,代码来源:Formatter.php

示例12: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     $valueBase = (string) $money->getAmount();
     $negative = false;
     if (substr($valueBase, 0, 1) === '-') {
         $negative = true;
         $valueBase = substr($valueBase, 1);
     }
     $fractionDigits = $this->formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
     $valueLength = strlen($valueBase);
     if ($valueLength > $fractionDigits) {
         $subunits = substr($valueBase, 0, $valueLength - $fractionDigits) . '.';
         $subunits .= substr($valueBase, $valueLength - $fractionDigits);
     } else {
         $subunits = '0.' . str_pad('', $fractionDigits - $valueLength, '0') . $valueBase;
     }
     if ($negative === true) {
         $subunits = '-' . $subunits;
     }
     return $this->formatter->formatCurrency($subunits, $money->getCurrency()->getCode());
 }
开发者ID:barryvdh,项目名称:money,代码行数:24,代码来源:IntlMoneyFormatter.php

示例13: set_up_display

 protected function set_up_display()
 {
     if (isset($this->category_id)) {
         $category = Category::find_by_id((int) $this->category_id);
         $this->category = $category->category;
         //    $this->unit_price = $category->unit_price;
         $this->price = $this->unit_price * $this->quantity;
         $this->price_company = $this->company_unit_price * $this->quantity;
         if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
             $formatter = new NumberFormatter('en_CH', NumberFormatter::CURRENCY);
             $this->price = $formatter->formatCurrency($this->price, 'CHF');
             $this->price_company = $formatter->formatCurrency($this->price_company, 'CHF');
             //    $this->unit_price=$formatter->formatCurrency($this->unit_price, 'CHF');
             //    $this->company_unit_price=$formatter->formatCurrency($this->company_unit_price, 'CHF');
         }
     }
     if (isset($this->project_id)) {
         $project = Project::find_by_id((int) $this->project_id);
         $this->project_code = $project->project_code;
     }
 }
开发者ID:kamy333,项目名称:rajah,代码行数:21,代码来源:_template.php

示例14: format

 /**
  * {@inheritdoc}
  */
 public function format($amount, $currency = null, $locale = null)
 {
     if (null === $currency) {
         $currency = $this->requestHelper->getCurrentCurrency();
     }
     $locale = $this->getLocale($locale);
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     if (false === ($result = $formatter->formatCurrency($amount, $currency))) {
         throw new CurrencyFormatterException($amount, $currency, $locale);
     }
     return $result;
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:15,代码来源:CurrencyFormatter.php

示例15: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     $valueBase = (string) $money->getAmount();
     $negative = false;
     if ($valueBase[0] === '-') {
         $negative = true;
         $valueBase = substr($valueBase, 1);
     }
     $subunit = $this->currencies->subunitFor($money->getCurrency());
     $valueLength = strlen($valueBase);
     if ($valueLength > $subunit) {
         $formatted = substr($valueBase, 0, $valueLength - $subunit) . '.';
         $formatted .= substr($valueBase, $valueLength - $subunit);
     } else {
         $formatted = '0.' . str_pad('', $subunit - $valueLength, '0') . $valueBase;
     }
     if ($negative === true) {
         $formatted = '-' . $formatted;
     }
     return $this->formatter->formatCurrency($formatted, $money->getCurrency()->getCode());
 }
开发者ID:squigg,项目名称:money,代码行数:24,代码来源:IntlMoneyFormatter.php


注:本文中的NumberFormatter::formatCurrency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。