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


PHP NumberFormatter::getAttribute方法代码示例

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


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

示例1: explodeTestData

 protected function explodeTestData($locale, $currencyCode)
 {
     // valid values for all currencies
     $validDomainValues = [(double) -10, (double) 0, (double) 10];
     // invalid values for all currencies
     $invalidDomainValues = [-1, 0, 1, null, false, true, "", "123", "foo", [], ['foo' => 'bar'], new \stdClass(), NAN, INF, -INF];
     $tmpValid = $validDomainValues;
     $tmpInvalid = $invalidDomainValues;
     // Build fraction digits test data
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $formatter->setTextAttribute($formatter::CURRENCY_CODE, $currencyCode);
     $fractionDigits = $formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
     $tmpValid[] = (double) (1 + pow(10, -$fractionDigits));
     $tmpInvalid[] = (double) (1 + pow(10, -($fractionDigits + 1)));
     $pi = pi();
     $tmpValid[] = round($pi, $fractionDigits);
     if ($fractionDigits > 2) {
         $tmpValid[] = round($pi, $fractionDigits - 1);
         $tmpValid[] = (double) (1 + pow(10, -($fractionDigits - 1)));
     }
     $tmpInvalid[] = round($pi, $fractionDigits + 1);
     $return = [];
     foreach ($tmpValid as $value) {
         $return[] = [$value, true];
     }
     foreach ($tmpInvalid as $value) {
         $return[] = [$value, false];
     }
     return $return;
 }
开发者ID:leodido,项目名称:moneylaundry,代码行数:30,代码来源:DomainTest.php

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

示例3: parse

 /**
  * {@inheritdoc}
  */
 public function parse($money, $forceCurrency = null)
 {
     $decimal = $this->formatter->parseCurrency($money, $currency);
     if ($decimal === false) {
         throw new ParserException('Cannot parse ' . $money . ' to Money. ' . $this->formatter->getErrorMessage());
     }
     $decimal = (string) $decimal;
     if (strpos($decimal, '.') !== false) {
         $decimal = str_replace('.', '', $decimal);
     } else {
         $decimal .= str_pad('', $this->formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS), '0');
     }
     if (substr($decimal, 0, 1) === '-') {
         $decimal = '-' . ltrim(substr($decimal, 1), '0');
     } else {
         $decimal = ltrim($decimal, '0');
     }
     if ($forceCurrency === null) {
         $forceCurrency = $currency;
     }
     return new Money($decimal, new Currency($forceCurrency));
 }
开发者ID:barryvdh,项目名称:money,代码行数:25,代码来源:IntlMoneyParser.php

示例4: check_number_locale

 public function check_number_locale()
 {
     $number_locale = $this->input->post('number_locale');
     $fmt = new \NumberFormatter($number_locale, \NumberFormatter::CURRENCY);
     $currency_symbol = empty($this->input->post('currency_symbol')) ? $fmt->getSymbol(\NumberFormatter::CURRENCY_SYMBOL) : $this->input->post('currency_symbol');
     if ($this->input->post('thousands_separator') == "false") {
         $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
     }
     $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $currency_symbol);
     $number_local_example = $fmt->format(1234567890.123);
     echo json_encode(array('success' => $number_local_example != FALSE, 'number_locale_example' => $number_local_example, 'currency_symbol' => $currency_symbol, 'thousands_separator' => $fmt->getAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL) != ''));
 }
开发者ID:gerarldlee,项目名称:opensourcepos,代码行数:12,代码来源:Config.php

示例5: getAttributeDataProvider

 public function getAttributeDataProvider()
 {
     $intlFormatter = new IntlNumberFormatter('en_US', \NumberFormatter::DECIMAL);
     $maxIntegerDigits = $intlFormatter->getAttribute(\NumberFormatter::MAX_INTEGER_DIGITS);
     return array(array('parse_int_only', 'DECIMAL', 'en_US', 0), array('parse_int_only', null, 'en_US', 0), array('GROUPING_USED', 'decimal', 'en_US', 1), array(\NumberFormatter::DECIMAL_ALWAYS_SHOWN, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::MAX_INTEGER_DIGITS, \NumberFormatter::DECIMAL, 'en_US', $maxIntegerDigits), array(\NumberFormatter::MIN_INTEGER_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 1), array(\NumberFormatter::INTEGER_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 1), array(\NumberFormatter::MAX_FRACTION_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 3), array(\NumberFormatter::MIN_FRACTION_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::MAX_FRACTION_DIGITS, \NumberFormatter::CURRENCY, 'en_US', 2), array(\NumberFormatter::MIN_FRACTION_DIGITS, \NumberFormatter::CURRENCY, 'en_US', 2), array(\NumberFormatter::FRACTION_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::MULTIPLIER, \NumberFormatter::DECIMAL, 'en_US', 1), array(\NumberFormatter::GROUPING_SIZE, \NumberFormatter::DECIMAL, 'en_US', 3), array(\NumberFormatter::ROUNDING_MODE, \NumberFormatter::DECIMAL, 'en_US', 4), array(\NumberFormatter::ROUNDING_INCREMENT, \NumberFormatter::DECIMAL, 'en_US', 0.0), array(\NumberFormatter::FORMAT_WIDTH, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::PADDING_POSITION, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::SECONDARY_GROUPING_SIZE, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::SIGNIFICANT_DIGITS_USED, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::MIN_SIGNIFICANT_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 1), array(\NumberFormatter::MAX_SIGNIFICANT_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 6));
 }
开发者ID:Maksold,项目名称:platform,代码行数:6,代码来源:NumberFormatterTest.php

示例6: getMaxDigits

 /**
  * Numero di decimali impostati per il locale
  *
  * @return bool|int
  */
 public function getMaxDigits()
 {
     $nft = new NF($this->locale, NF::DECIMAL);
     return $nft->getAttribute(NF::MAX_FRACTION_DIGITS);
 }
开发者ID:beggiatom,项目名称:L5Intl,代码行数:10,代码来源:Number.php


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