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


PHP NumberFormatter::getErrorMessage方法代码示例

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


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

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

示例2: parse

 /**
  * {@inheritdoc}
  */
 public function parse($money, $forceCurrency = null)
 {
     if (!is_string($money)) {
         throw new ParserException('Formatted raw money should be string, e.g. $1.00');
     }
     $currencyCode = null;
     $decimal = $this->formatter->parseCurrency($money, $currencyCode);
     if (null !== $forceCurrency) {
         $currencyCode = $forceCurrency;
     }
     $currency = new Currency($currencyCode);
     if (false === $decimal) {
         throw new ParserException('Cannot parse ' . $money . ' to Money. ' . $this->formatter->getErrorMessage());
     }
     $decimal = (string) $decimal;
     $subunit = $this->currencies->subunitFor($currency);
     $decimalPosition = strpos($decimal, '.');
     if (false !== $decimalPosition) {
         $decimalLength = strlen($decimal);
         $fractionDigits = $decimalLength - $decimalPosition - 1;
         $decimal = str_replace('.', '', $decimal);
         $decimal = Number::roundMoneyValue($decimal, $subunit, $fractionDigits);
         if ($fractionDigits > $subunit) {
             $decimal = substr($decimal, 0, $decimalPosition + $subunit);
         } elseif ($fractionDigits < $subunit) {
             $decimal .= str_pad('', $subunit - $fractionDigits, '0');
         }
     } else {
         $decimal .= str_pad('', $subunit, '0');
     }
     if ('-' === $decimal[0]) {
         $decimal = '-' . ltrim(substr($decimal, 1), '0');
     } else {
         $decimal = ltrim($decimal, '0');
     }
     return new Money($decimal, $currency);
 }
开发者ID:squigg,项目名称:money,代码行数:40,代码来源:IntlMoneyParser.php

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

示例4: 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);
         }
         $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:radmar,项目名称:APYDataGridBundle,代码行数:36,代码来源:NumberColumn.php


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