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


PHP NumberFormatter::getTextAttribute方法代码示例

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


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

示例1: getCurrencyCode

 /**
  * Retrieve the currency code.
  *
  * @return string|null
  */
 public function getCurrencyCode()
 {
     if (!isset($this->options['currency_code'])) {
         if ($this->formatter) {
             return $this->formatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE);
         }
         return null;
     }
     return $this->options['currency_code'];
 }
开发者ID:leodido,项目名称:moneylaundry,代码行数:15,代码来源:AbstractFilter.php

示例2: getRules

 private function getRules($locale, $type)
 {
     $formatter = new \NumberFormatter($locale, $type);
     $rules = [];
     $rawRules = explode(';', trim($formatter->getTextAttribute(\NumberFormatter::PUBLIC_RULESETS), ';'));
     $default = $formatter->getTextAttribute(\NumberFormatter::DEFAULT_RULESET);
     foreach ($rawRules as $rule) {
         $rules[$rule] = $rule === $default;
     }
     return $rules;
 }
开发者ID:samdark,项目名称:intl-icu-data-tables,代码行数:11,代码来源:SiteController.php

示例3: getDisplayedValue

 public function getDisplayedValue($value)
 {
     if ($value !== null && $value !== '') {
         $formatter = new \NumberFormatter($this->locale, $this->style);
         if ($this->precision !== null) {
             $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision);
             $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $this->roundingMode);
         }
         if ($this->ruleSet !== null) {
             $formatter->setTextAttribute(\NumberFormatter::DEFAULT_RULESET, $this->ruleSet);
         }
         if ($this->maxFractionDigits !== null) {
             $formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $this->maxFractionDigits);
         }
         $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $this->grouping);
         if ($this->style === \NumberFormatter::PERCENT && !$this->fractional) {
             $value /= 100;
         }
         if ($this->style === \NumberFormatter::CURRENCY) {
             if ($this->currencyCode === null) {
                 $this->currencyCode = $formatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE);
             }
             if (strlen($this->currencyCode) !== 3) {
                 throw new TransformationFailedException('Your locale definition is not complete, you have to define a language and a country. (.e.g en_US, fr_FR)');
             }
             $value = $formatter->formatCurrency($value, $this->currencyCode);
         } else {
             $value = $formatter->format($value);
         }
         if (intl_is_failure($formatter->getErrorCode())) {
             throw new TransformationFailedException($formatter->getErrorMessage());
         }
         if (key_exists((string) $value, $this->values)) {
             $value = $this->values[$value];
         }
         return $value;
     }
     return '';
 }
开发者ID:deeky666,项目名称:APYDataGridBundle,代码行数:39,代码来源:NumberColumn.php

示例4: getTextAttribute

 /**
  * @inheritdoc
  */
 public function getTextAttribute($attr)
 {
     return isset($this->attributes[$attr]) ? $this->attributes[$attr] : parent::getTextAttribute($attr);
 }
开发者ID:zsdregas,项目名称:number-formatter,代码行数:7,代码来源:NumberFormatter.php

示例5: testGetTextAttribute

 public function testGetTextAttribute()
 {
     $this->skipIfIntlExtensionIsNotLoaded();
     $intlDecimalFormatter = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
     $intlCurrencyFormatter = new \NumberFormatter('en', \NumberFormatter::CURRENCY);
     $stubDecimalFormatter = $this->getStubFormatterWithDecimalStyle();
     $stubCurrencyFormatter = $this->getStubFormatterWithCurrencyStyle();
     for ($i = 0; $i <= 5; $i++) {
         $this->assertSame($stubDecimalFormatter->getTextAttribute($i), $intlDecimalFormatter->getTextAttribute($i), $i);
         $this->assertSame($stubCurrencyFormatter->getTextAttribute($i), $intlCurrencyFormatter->getTextAttribute($i), 'fooo ' . $i);
     }
 }
开发者ID:senthil-r-wiredelta,项目名称:meilleure-visite,代码行数:12,代码来源:StubNumberFormatterTest.php

示例6: getCurrCode

 public function getCurrCode($locale = NULL)
 {
     if ($locale === NULL) {
         $locale = $this->locale;
     }
     if (extension_loaded('intl')) {
         $formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
         return $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
     }
 }
开发者ID:robotamer,项目名称:oldstuff,代码行数:10,代码来源:Localize.php

示例7: nReal

 /**
  * Mostra o Valor no real Formatado
  * @param float $number
  * @param boolean $fixed
  * @param boolean $symbol
  * @param integer $decimals
  * @return string
  */
 public static function nReal($number, $decimals = 2, $symbol = true, $fixed = true)
 {
     if (is_null($number) || empty(self::onlyNumbers($number))) {
         return '';
     }
     $formater = new \NumberFormatter("pt-BR", \NumberFormatter::CURRENCY);
     $formater->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $fixed ? $decimals : 1);
     if ($decimals === false) {
         $decimals = 2;
         preg_match_all('/[0-9][^0-9]([0-9]+)/', $number, $matches);
         if (!empty($matches[1])) {
             $decimals = strlen(rtrim($matches[1][0], 0));
         }
     }
     $formater->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
     if (!$symbol) {
         $pattern = preg_replace("/[¤]/", '', $formater->getPattern());
         $formater->setPattern($pattern);
     } else {
         // ESPAÇO DEPOIS DO SIMBOLO
         $pattern = str_replace("¤", "¤ ", $formater->getPattern());
         $formater->setPattern($pattern);
     }
     return $formater->formatCurrency($number, $formater->getTextAttribute(\NumberFormatter::CURRENCY_CODE));
 }
开发者ID:eduardokum,项目名称:laravel-boleto,代码行数:33,代码来源:Util.php


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