當前位置: 首頁>>代碼示例>>PHP>>正文


PHP NumberFormatter::getErrorCode方法代碼示例

本文整理匯總了PHP中NumberFormatter::getErrorCode方法的典型用法代碼示例。如果您正苦於以下問題:PHP NumberFormatter::getErrorCode方法的具體用法?PHP NumberFormatter::getErrorCode怎麽用?PHP NumberFormatter::getErrorCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NumberFormatter的用法示例。


在下文中一共展示了NumberFormatter::getErrorCode方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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);
     $position = 0;
     $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
     if (intl_is_failure($formatter->getErrorCode()) || $position < strlen($value)) {
         /** @var Decimal $constraint */
         $this->context->addViolation($constraint->message, ['{{ value }}' => $this->formatValue($value)]);
     }
 }
開發者ID:hafeez3000,項目名稱:orocommerce,代碼行數:19,代碼來源:DecimalValidator.php

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

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

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

示例5: throwNumberFormatterException

 /**
  * Throws an Exception when number cannot be formatted
  * @param IntlNumberFormatter $intlFormatter
  * @param int|string|float $number
  * @throws Exception\RuntimeException
  */
 protected function throwNumberFormatterException(IntlNumberFormatter $intlFormatter, $number)
 {
     $error_code = $intlFormatter->getErrorCode();
     if (is_scalar($number)) {
         $val = (string) $number;
     } else {
         $val = 'type: ' . gettype($number);
     }
     throw new Exception\RuntimeException(__METHOD__ . " Cannot format value '{$val}', Intl/NumberFormatter error code: {$error_code}.");
 }
開發者ID:robocoder,項目名稱:solublecomponents,代碼行數:16,代碼來源:NumberFormatter.php


注:本文中的NumberFormatter::getErrorCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。