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


PHP NumberFormatter::setAttribute方法代码示例

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


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

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

示例2: getNumberFormatter

 /**
  * Returns a preconfigured \NumberFormatter instance
  *
  * @return \NumberFormatter
  */
 protected function getNumberFormatter()
 {
     $formatter = new \NumberFormatter($this->locale, \NumberFormatter::DECIMAL);
     if ($this->getOption('precision') !== null) {
         $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->getOption('precision'));
     }
     $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $this->getOption('grouping'));
     return $formatter;
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:14,代码来源:NumberToLocalizedStringTransformer.php

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

示例4: convertDefaultToLocalizedFromLocale

 /**
  * {@inheritdoc}
  */
 public function convertDefaultToLocalizedFromLocale($number, $locale)
 {
     if (null === $number || '' === $number) {
         return $number;
     }
     $numberFormatter = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
     if (is_numeric($number) && floor($number) != $number) {
         $numberFormatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 2);
         $numberFormatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 4);
     }
     return $numberFormatter->format($number);
 }
开发者ID:qrz-io,项目名称:pim-community-dev,代码行数:15,代码来源:AbstractNumberLocalizer.php

示例5: parse_decimals

function parse_decimals($number)
{
    // ignore empty strings and return
    if (empty($number)) {
        return $number;
    }
    $config = get_instance()->config;
    $fmt = new \NumberFormatter($config->item('number_locale'), \NumberFormatter::DECIMAL);
    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item('quantity_decimals'));
    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item('quantity_decimals'));
    return $fmt->parse($number);
}
开发者ID:gerarldlee,项目名称:opensourcepos,代码行数:12,代码来源:locale_helper.php

示例6: format

 /**
  * {@inheritdoc}
  */
 public function format($value, array $options = [])
 {
     if (!is_numeric($value)) {
         throw new InvalidTypeException(sprintf('The number formatter expects a numeric value, got "%s".', is_object($value) ? get_class($value) : gettype($value)));
     }
     $scale = isset($options['scale']) ? $options['scale'] : 2;
     $rounding = isset($options['rounding']) ? $options['rounding'] : \NumberFormatter::ROUND_HALFUP;
     $grouping = isset($options['grouping']) ? $options['grouping'] : false;
     $formatter = new \NumberFormatter($this->localeContext->getLocale(), \NumberFormatter::DECIMAL);
     $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $scale);
     $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $rounding);
     $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $grouping);
     return str_replace(" ", ' ', $formatter->format($value));
 }
开发者ID:php-lug,项目名称:lug,代码行数:17,代码来源:NumberFormatter.php

示例7: percent

 /**
  * Il valore viene convertito in percentuale con relativo simbolo
  *
  * - Se non vengono passati i decimali vengono presentati quelli impostati dal locale
  * - Se sono presenti vengono presentati sono quelli indicati es. 2 decimali 10,123 -> 10,12%, 10,456 -> 10,46%
  *
  * @param $number
  * @param null $decimal
  * @return bool|string
  */
 public function percent($number, $decimal = null)
 {
     is_null($decimal) ? $decimal = $this->getMaxDigits() : null;
     $number = $number / 100;
     $nft = new NF($this->locale, NF::PERCENT);
     $nft->setAttribute(NF::FRACTION_DIGITS, $decimal);
     return $nft->format($number);
 }
开发者ID:beggiatom,项目名称:L5Intl,代码行数:18,代码来源:Number.php

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

示例9: getDefaultNumberFormatter

 protected function getDefaultNumberFormatter($currencyCode, $locale = null)
 {
     if (is_null($locale)) {
         $locale = \Locale::getDefault();
     }
     $numberFormatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $numberFormatter->setTextAttribute(\NumberFormatter::CURRENCY_CODE, $currencyCode);
     $numberFormatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->decimals);
     return $numberFormatter;
 }
开发者ID:lakhman,项目名称:TbbcMoneyBundle,代码行数:10,代码来源:MoneyFormatter.php

示例10: format

 /**
  * {@inheritdoc}
  */
 public function format($value)
 {
     $uiLocale = $this->getUiLocale();
     if (null === $uiLocale) {
         return $value;
     }
     $numberFormatter = new \NumberFormatter($uiLocale, \NumberFormatter::DECIMAL);
     $numberFormatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->getDecimalCount($value));
     return $numberFormatter->format($value);
 }
开发者ID:paulclarkin,项目名称:pim-community-dev,代码行数:13,代码来源:NumberFormatter.php

示例11: format

 /**
  * {@inheritdoc}
  */
 public function format($value, array $options = array())
 {
     if (null === $value) {
         return $options['null_value'];
     }
     if (!is_numeric($value)) {
         throw FormatterException::invalidType($this, $value, 'numeric value');
     }
     $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
     if (null !== $options['precision']) {
         $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $options['precision']);
         $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $options['rounding_mode']);
     }
     $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $options['grouping']);
     $value = $formatter->format($value);
     if (intl_is_failure($formatter->getErrorCode())) {
         throw FormatterException::intlError($this, $formatter->getErrorMessage());
     }
     return $value;
 }
开发者ID:jfsimon,项目名称:datagrid,代码行数:23,代码来源:NumberFormatter.php

示例12: format

 /**
  * Format the specified number to a string with the specified number of
  * fractional digits.
  *
  * @param
  *        	double d
  *        	The number to format.
  * @param
  *        	int digits
  *        	The number of fractional digits.
  * @return string The number formatted as a string.
  */
 public function format($d, $digits)
 {
     $this->synchronized(function ($thread) {
         if (is_infinite($d) || is_nan($d)) {
             return "0";
         }
         $this->numberFormatter->setAttribute(\NumberFormatter::GROUPING_USED, false);
         $this->numberFormatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $digits);
         return $this->numberFormatter->format($d);
     });
 }
开发者ID:katrinaniolet,项目名称:encog-php-core,代码行数:23,代码来源:CSVFormat.php

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

示例14: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value)) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
     $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, \NumberFormatter::ROUND_DOWN);
     $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, 0);
     $formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
     $formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 0);
     $decimalSeparator = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
     $position = 0;
     $formatter->parse($value, PHP_INT_SIZE == 8 ? $formatter::TYPE_INT64 : $formatter::TYPE_INT32, $position);
     if (intl_is_failure($formatter->getErrorCode()) || strpos($value, $decimalSeparator) !== false || $position < strlen($value)) {
         /** @var Integer $constraint */
         $this->context->addViolation($constraint->message, ['{{ value }}' => $this->formatValue($value)]);
     }
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:24,代码来源:IntegerValidator.php

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


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