Neos\Flow\I18n\Formatter\NumberFormatter::formatNumberWithCustomPattern PHP 메소드

formatNumberWithCustomPattern() 공개 메소드

Format must obey syntax defined in CLDR specification, excluding unimplemented features (see documentation for this class). Format is remembered in this classes cache and won't be parsed again for some time.
public formatNumberWithCustomPattern ( mixed $number, string $format, Locale $locale ) : string
$number mixed Float or int, can be negative, can be NaN or infinite
$format string Format string
$locale Neos\Flow\I18n\Locale A locale used for finding symbols array
리턴 string Formatted number. Will return string-casted version of $number if pattern is not valid / supported
    public function formatNumberWithCustomPattern($number, $format, Locale $locale)
    {
        return $this->doFormattingWithParsedFormat($number, $this->numbersReader->parseCustomFormat($format), $this->numbersReader->getLocalizedSymbolsForLocale($locale));
    }

Usage Example

 /**
  * @test
  * @dataProvider customFormatsAndFormatterNumbers
  */
 public function formattingUsingCustomPatternWorks($number, $format, array $parsedFormat, $expectedResult)
 {
     $mockNumbersReader = $this->createMock(I18n\Cldr\Reader\NumbersReader::class);
     $mockNumbersReader->expects($this->once())->method('parseCustomFormat')->with($format)->will($this->returnValue($parsedFormat));
     $mockNumbersReader->expects($this->once())->method('getLocalizedSymbolsForLocale')->with($this->sampleLocale)->will($this->returnValue($this->sampleLocalizedSymbols));
     $formatter = new I18n\Formatter\NumberFormatter();
     $formatter->injectNumbersReader($mockNumbersReader);
     $result = $formatter->formatNumberWithCustomPattern($number, $format, $this->sampleLocale);
     $this->assertEquals($expectedResult, $result);
 }