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


PHP NumberFormatter::parse方法代码示例

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


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

示例1: createResponse

 /**
  * @param array    $data
  * @param Campaign $campaign
  *
  * @return Response
  */
 public function createResponse(array $data, Campaign $campaign)
 {
     $response = new Response();
     $response->setCampaign($campaign);
     $response->setGrossAnnualSalary($this->numberFormatter->parse($data["gross_annual_salary"]));
     $response->setVariableAnnualSalary($this->numberFormatter->parse($data["variable_annual_salary"]));
     $response->setAnnualSalary($this->numberFormatter->parse($data["annual_salary"]));
     $response->setSalarySatisfaction($this->numberFormatter->parse($data["salary_satisfaction"]));
     $response->setStatus($this->enums->getEnums('status')->getIdByLabel($data["status"]));
     $response->setJobTitle($this->enums->getEnums('job_title')->getIdByLabel($data["job_title"]));
     $response->setExperience($this->enums->getEnums('experience')->getIdByLabel($data["experience"]));
     $response->setInitialTraining($this->enums->getEnums('initial_training')->getIdByLabel($data["initial_training"]));
     $response->setCompanyType($this->enums->getEnums('company_type')->getIdByLabel($data["company_type"]));
     $response->setCompanySize($this->enums->getEnums('company_size')->getIdByLabel($data["company_size"]));
     $department = new Departments();
     if (in_array($data["company_department"], array_keys($department->getAll()))) {
         $response->setCompanyDepartment($data["company_department"]);
     }
     $response->setJobInterest($this->enums->getEnums('job_interest')->getIdByLabel($data["job_interest"]));
     $response->setPhpVersion($this->enums->getEnums('php_version')->getIdByLabel($data["php_version"]));
     $response->setPhpStrength($this->enums->getEnums('php_strength')->getIdByLabel($data["php_strength"]));
     $response->setHasRecentTraining("oui" === strtolower($data["has_formation"]));
     $response->setRecentTrainingHadSalaryImpact("oui" === strtolower($data["formation_impact"]));
     if ("oui" === strtolower($data['has_certification'])) {
         $this->addCertification($response, explode(', ', $data['certification_list']));
     }
     if (strlen(trim($data["speciality"])) !== 0) {
         $this->addSpeciality($response, explode(', ', $data['speciality']));
     }
     $response->setGender($this->enums->getEnums('gender')->getIdByLabel($data["gender"]));
     return $response;
 }
开发者ID:Volyz,项目名称:barometre,代码行数:38,代码来源:ResponseFactory.php

示例2: convertToDatabaseValue

 /**
  * @param  string|int|float|null                    $value
  * @param  Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @return mixed
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return;
     }
     $formatter = new \NumberFormatter('pt_BR', \NumberFormatter::DECIMAL);
     $formatted = $formatter->parse($value);
     return $formatted;
 }
开发者ID:lafaiDev,项目名称:suive_com,代码行数:14,代码来源:BrPriceType.php

示例3: ut_main

function ut_main()
{
    setlocale(LC_ALL, 'de_DE');
    $fmt = new NumberFormatter('sl_SI.UTF-8', NumberFormatter::DECIMAL);
    $num = "1.234.567,891";
    $res_str = $fmt->parse($num) . "\n";
    $res_str .= setlocale(LC_NUMERIC, 0);
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:bug67052.php

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

示例5: latinizeDigits

 /**
  * Replaces localized digits in $str with latin digits.
  *
  * @param string $str
  * @return string Latinized string
  */
 protected function latinizeDigits($str)
 {
     $result = '';
     $num = new \NumberFormatter($this->locale, \NumberFormatter::DECIMAL);
     preg_match_all('/.[\\x80-\\xBF]*/', $str, $matches);
     foreach ($matches[0] as $char) {
         $pos = 0;
         $parsedChar = $num->parse($char, \NumberFormatter::TYPE_INT32, $pos);
         $result .= $pos ? $parsedChar : $char;
     }
     return $result;
 }
开发者ID:Exlord,项目名称:IntlDateTime,代码行数:18,代码来源:IntlDateTime.php

示例6: 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);
    if (empty($config->item('thousands_separator'))) {
        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    }
    return $fmt->parse($number);
}
开发者ID:mnapier,项目名称:opensourcepos,代码行数:13,代码来源:locale_helper.php

示例7: ut_main

function ut_main()
{
    $res_str = "";
    $de_locale = "de_DE.UTF-8";
    $fmt = new NumberFormatter("de", NumberFormatter::DECIMAL);
    $numeric = $fmt->parse("1234,56");
    $res_str .= "{$numeric}\n";
    setlocale(LC_ALL, $de_locale);
    $fmt = new NumberFormatter("de", NumberFormatter::DECIMAL);
    $numeric = $fmt->parse("1234,56");
    setlocale(LC_ALL, "C");
    // reset for printing
    $res_str .= "{$numeric}\n";
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:15,代码来源:bug14562.php

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

示例9: parse

 /**
  * Parse the specified string to a double.
  *
  * @param
  *        	string str
  *        	The string to parse.
  * @return double The parsed number.
  */
 public function parse($str)
 {
     $this->synchronized(function ($thread) {
         try {
             if ($str === "?") {
                 return \NAN;
             }
             if (strtolower($str) === strtolower("NaN")) {
                 return \NAN;
             } else {
                 return doubleval($this->numberFormatter->parse(doubleval(trim($str))));
             }
         } catch (Exception $e) {
             throw new CSVError("Error:" + $e->getMessage() + " on [" + $str + "], decimal:" + $this->decimal + ",sep: " + $this->separator);
         }
     });
 }
开发者ID:katrinaniolet,项目名称:encog-php-core,代码行数:25,代码来源:CSVFormat.php

示例10: testNumberFormatter

 /**
  * @dataProvider getParseData
  */
 public function testNumberFormatter($input, $output, $expectExtraChars = false, $maxIcuVersion = null)
 {
     if (!class_exists('NumberFormatter')) {
         $this->markTestSkipped('ext/intl not loaded');
         return;
     }
     $icuVersion = $this->getIcuVersion();
     if ($maxIcuVersion && version_compare($icuVersion, $maxIcuVersion, '>')) {
         $this->markTestSkipped('ICU Version to big for this test. Version is ' . $icuVersion . ' max allowed ' . $maxIcuVersion);
         return;
     }
     $input = trim($input);
     $yay = 0;
     $x = new NumberFormatter("en_US", NumberFormatter::DECIMAL);
     $x->setAttribute(NumberFormatter::LENIENT_PARSE, true);
     $parsed = $x->parse($input, NumberFormatter::TYPE_DOUBLE, $yay);
     $this->assertEquals($output, $parsed);
     $this->assertEquals($expectExtraChars, $yay < strlen($input));
 }
开发者ID:horros,项目名称:agavi,代码行数:22,代码来源:AgaviDecimalFormatterTest.php

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

示例12: formatDecimalFromLocale

 /**
  * Returns a machine workable decimal according to locale. 
  * @param string $locale e.g. en_US
  * @param string $decimal
  * @param int $max_digits
  * @param int $min_digits
  * @return decimal $res
  */
 public static function formatDecimalFromLocale($locale, $decimal, $min_digits = 2, $max_digits = 2)
 {
     $f = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
     if ($min_digits) {
         $f->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $min_digits);
     }
     if ($max_digits) {
         $f->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $max_digits);
         // by default some locales got max 2 fraction digits, that is probably not what you want
     }
     return $f->parse($decimal);
 }
开发者ID:diversen,项目名称:simple-php-classes,代码行数:20,代码来源:intl.php

示例13: beforeSave

 /**
  * Prepare data for save
  *
  * @return $this
  * @throws LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function beforeSave()
 {
     // prevent overriding product data
     if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
         throw new LocalizedException(__('The attribute code \'%1\' is reserved by system. Please try another attribute code', $this->_data['attribute_code']));
     }
     /**
      * Check for maximum attribute_code length
      */
     if (isset($this->_data['attribute_code']) && !\Zend_Validate::is($this->_data['attribute_code'], 'StringLength', ['max' => self::ATTRIBUTE_CODE_MAX_LENGTH])) {
         throw new LocalizedException(__('An attribute code must be fewer than %1 characters.', self::ATTRIBUTE_CODE_MAX_LENGTH));
     }
     $defaultValue = $this->getDefaultValue();
     $hasDefaultValue = (string) $defaultValue != '';
     if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
         $numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL);
         $defaultValue = $numberFormatter->parse($defaultValue);
         if ($defaultValue === false) {
             throw new LocalizedException(__('Invalid default decimal value'));
         }
         $this->setDefaultValue($defaultValue);
     }
     if ($this->getBackendType() == 'datetime') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Datetime');
         }
         if (!$this->getFrontendModel()) {
             $this->setFrontendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\Datetime');
         }
         // save default date value as timestamp
         if ($hasDefaultValue) {
             $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
             try {
                 $defaultValue = $this->dateTimeFormatter->formatObject(new \DateTime($defaultValue), $format);
                 $this->setDefaultValue($defaultValue);
             } catch (\Exception $e) {
                 throw new LocalizedException(__('Invalid default date'));
             }
         }
     }
     if ($this->getBackendType() == 'gallery') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\DefaultBackend');
         }
     }
     return parent::beforeSave();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:55,代码来源:Attribute.php

示例14:

<?php

$formatter = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
$value = $formatter->parse('2147483647', \NumberFormatter::TYPE_INT32);
var_dump($value);
$formatter = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
$value = $formatter->parse('2147483650', \NumberFormatter::TYPE_INT64);
var_dump($value);
开发者ID:badlamer,项目名称:hhvm,代码行数:8,代码来源:bug59597_32.php

示例15: parse

 /**
  * Use this method to parse currency string.
  *
  * <code>
  * $amount   = 1,500.25;
  *
  * $language         = JFactory::getLanguage();
  * $moneyFormatter   = new NumberFormatter($language->getTag(), NumberFormatter::PATTERN_DECIMAL, $this->params->get('currency_pattern'));
  *
  * $money   = new Prism\Money\Money($moneyFormatter);
  * $money->setValue($amount);
  *
  * // Will return 1500.25.
  * $goal = $money->parse();
  * </code>
  *
  * @return string
  */
 public function parse()
 {
     return $this->formatter->parse($this->amount, \NumberFormatter::TYPE_DOUBLE);
 }
开发者ID:ITPrism,项目名称:CrowdfundingDistribution,代码行数:22,代码来源:Money.php


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