• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP NumberFormatter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: render

 public function render(\Erebot\IntlInterface $translator)
 {
     $locale = $translator->getLocale(\Erebot\IntlInterface::LC_NUMERIC);
     $formatter = new \NumberFormatter($locale, \NumberFormatter::IGNORE);
     $result = (string) $formatter->format($this->value, \NumberFormatter::TYPE_INT32);
     return $result;
 }
开发者ID:erebot,项目名称:styling,代码行数:7,代码来源:IntegerVariable.php


示例3: decimalNumber

 /**
  * Formatação de numero decimal
  * @param float/integer $value
  * @param integer $precision
  * @param string $language
  * @return float
  */
 public static function decimalNumber($value, $precision = 2, $language = 'pt_BR')
 {
     $valDecimal = new \NumberFormatter($language, \NumberFormatter::DECIMAL);
     $valDecimal->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $precision);
     $valDecimal->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $precision);
     return $valDecimal->format((double) $value, \NumberFormatter::TYPE_DOUBLE);
 }
开发者ID:cityware,项目名称:city-format,代码行数:14,代码来源:Number.php


示例4: currencySymbolFunction

 public function currencySymbolFunction($locale)
 {
     $locale = $locale == null ? \Locale::getDefault() : $locale;
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $symbol = $formatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
     return $symbol;
 }
开发者ID:alisyihab,项目名称:sisdik,代码行数:7,代码来源:LanggasExtension.php


示例5: buildView

 /**
  * @param FormView      $view
  * @param FormInterface $form
  * @param array         $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $dataType = self::DATA_INTEGER;
     if (isset($options['data_type'])) {
         $dataType = $options['data_type'];
     }
     $formatterOptions = array();
     switch ($dataType) {
         case self::PERCENT:
             $formatterOptions['decimals'] = 2;
             $formatterOptions['grouping'] = false;
             $formatterOptions['percent'] = true;
             break;
         case self::DATA_DECIMAL:
             $formatterOptions['decimals'] = 2;
             $formatterOptions['grouping'] = true;
             break;
         case self::DATA_INTEGER:
         default:
             $formatterOptions['decimals'] = 0;
             $formatterOptions['grouping'] = false;
     }
     $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
     $formatterOptions['orderSeparator'] = $formatterOptions['grouping'] ? $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL) : '';
     $formatterOptions['decimalSeparator'] = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
     $view->vars['formatter_options'] = array_merge($formatterOptions, $options['formatter_options']);
 }
开发者ID:xamin123,项目名称:platform,代码行数:32,代码来源:NumberFilterType.php


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: bytesToHuman

 public function bytesToHuman($bytes, $precision = 2)
 {
     $suffixes = ['bytes', 'kB', 'MB', 'GB', 'TB'];
     $formatter = new \NumberFormatter($this->translator->getLocale(), \NumberFormatter::PATTERN_DECIMAL, 0 === $precision ? '#' : '.' . str_repeat('#', $precision));
     $exp = floor(log($bytes, 1024));
     return $formatter->format($bytes / pow(1024, floor($exp))) . ' ' . $this->translator->trans($suffixes[$exp]);
 }
开发者ID:stof,项目名称:Gitiki,代码行数:7,代码来源:CoreExtension.php


示例13: 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


示例14: porExtenso

 /**
  * Retorna número por extenso
  * @param int $number 
  * @return string número por extenso
  */
 public function porExtenso($number)
 {
     if (!is_numeric($number)) {
         return false;
     }
     $fmt = new \NumberFormatter('br', \NumberFormatter::SPELLOUT);
     return $fmt->format($number);
 }
开发者ID:adaoex,项目名称:zf2-base,代码行数:13,代码来源:Numero.php


示例15: getNumberFormatter

 /**
  * {@inheritDoc}
  */
 protected function getNumberFormatter()
 {
     $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
     if (null !== $this->precision) {
         $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision);
     }
     return $formatter;
 }
开发者ID:Maksold,项目名称:platform,代码行数:11,代码来源:PercentToLocalizedStringTransformer.php


示例16: 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


示例17: spell

 /**
  * 数值转为中文拼读
  */
 public static function spell($number, $capital = false)
 {
     $formatter = new \NumberFormatter('zh_CN', \NumberFormatter::SPELLOUT);
     $sentence = $formatter->format($number);
     if ($capital) {
         $sentence = self::mbStrtr($sentence, self::$chars, self::$caps);
     }
     return $sentence;
 }
开发者ID:azhai,项目名称:CuteLib,代码行数:12,代码来源:Word.php


示例18: Repeat

 public static function Repeat($times)
 {
     $list = new ArrayList();
     $formatter = new NumberFormatter('en-NZ', NumberFormatter::SPELLOUT);
     for ($i = 1; $i <= $times; $i++) {
         $list->push(array('Num' => $i, 'Word' => ucwords(strtolower($formatter->format($i)))));
     }
     return $list;
 }
开发者ID:helpfulrobot,项目名称:webfox-silverstripe-helpers,代码行数:9,代码来源:HelpersTemplateProvider.php


示例19: convertToDatabaseValue

 /**
  * @param  string|int|float|null                    $value
  * @param  Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @return mixed
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return;
     }
     $formatter = new \NumberFormatter('pt_BR', \NumberFormatter::DECIMAL);
     $formatted = $formatter->parse($value);
     return $formatted;
 }
开发者ID:lafaiDev,项目名称:suive_com,代码行数:14,代码来源:BrPriceType.php


示例20: render

 public function render(\Erebot\IntlInterface $translator)
 {
     $locale = $translator->getLocale(\Erebot\IntlInterface::LC_NUMERIC);
     $formatter = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
     $formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
     $formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 100);
     $result = (string) $formatter->format($this->value);
     return $result;
 }
开发者ID:erebot,项目名称:styling,代码行数:9,代码来源:FloatVariable.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP NumberValue类代码示例发布时间:2022-05-23
下一篇:
PHP Number类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap