Neos\Flow\I18n\Parser\NumberParser::parsePercentNumber PHP Method

parsePercentNumber() public method

Parses percent number using proper format from CLDR.
public parsePercentNumber ( string $numberToParse, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed
$numberToParse string Number to be parsed
$locale Neos\Flow\I18n\Locale Locale to use
$formatLength string One of NumbersReader FORMAT_LENGTH constants
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Parsed float number or FALSE on failure
    public function parsePercentNumber($numberToParse, Locale $locale, $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT, $strictMode = true)
    {
        NumbersReader::validateFormatLength($formatLength);
        return $this->doParsingWithParsedFormat($numberToParse, $this->numbersReader->parseFormatFromCldr($locale, NumbersReader::FORMAT_TYPE_PERCENT, $formatLength), $this->numbersReader->getLocalizedSymbolsForLocale($locale), $strictMode);
    }

Usage Example

 /**
  * Checks if the given value is a valid number.
  *
  * @param mixed $value The value that should be validated
  * @return void
  * @api
  * @todo Currency support should be added when it will be supported by NumberParser
  */
 protected function isValid($value)
 {
     if (!isset($this->options['locale'])) {
         $locale = $this->localizationService->getConfiguration()->getDefaultLocale();
     } elseif (is_string($this->options['locale'])) {
         $locale = new I18n\Locale($this->options['locale']);
     } elseif ($this->options['locale'] instanceof I18n\Locale) {
         $locale = $this->options['locale'];
     } else {
         $this->addError('The "locale" option can be only set to string identifier, or Locale object.', 1281286579);
         return;
     }
     $strictMode = $this->options['strictMode'];
     $formatLength = $this->options['formatLength'];
     NumbersReader::validateFormatLength($formatLength);
     $formatType = $this->options['formatType'];
     NumbersReader::validateFormatType($formatType);
     if ($formatType === NumbersReader::FORMAT_TYPE_PERCENT) {
         if ($this->numberParser->parsePercentNumber($value, $locale, $formatLength, $strictMode) === false) {
             $this->addError('A valid percent number is expected.', 1281452093);
         }
         return;
     } else {
         if ($this->numberParser->parseDecimalNumber($value, $locale, $formatLength, $strictMode) === false) {
             $this->addError('A valid decimal number is expected.', 1281452094);
         }
     }
 }
All Usage Examples Of Neos\Flow\I18n\Parser\NumberParser::parsePercentNumber