yii\i18n\Formatter::asSpellout PHP Method

asSpellout() public method

This function requires the PHP intl extension to be installed.
public asSpellout ( mixed $value ) : string
$value mixed the value to be formatted
return string the formatted result.
    public function asSpellout($value)
    {
        if ($value === null) {
            return $this->nullDisplay;
        }
        $value = $this->normalizeNumericValue($value);
        if ($this->_intlLoaded) {
            $f = $this->createNumberFormatter(NumberFormatter::SPELLOUT);
            if (($result = $f->format($value)) === false) {
                throw new InvalidParamException('Formatting number as spellout failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
            }
            return $result;
        } else {
            throw new InvalidConfigException('Format as Spellout is only supported when PHP intl extension is installed.');
        }
    }

Usage Example

Beispiel #1
0
 public function testIntlAsSpellout()
 {
     $this->assertSame('one hundred twenty-three', $this->formatter->asSpellout(123));
     $this->formatter->locale = 'de_DE';
     $this->assertSame('ein­hundert­drei­und­zwanzig', $this->formatter->asSpellout(123));
     // null display
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asSpellout(null));
 }