本文整理汇总了PHP中NumberFormatter::getTextAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP NumberFormatter::getTextAttribute方法的具体用法?PHP NumberFormatter::getTextAttribute怎么用?PHP NumberFormatter::getTextAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumberFormatter
的用法示例。
在下文中一共展示了NumberFormatter::getTextAttribute方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCurrencyCode
/**
* Retrieve the currency code.
*
* @return string|null
*/
public function getCurrencyCode()
{
if (!isset($this->options['currency_code'])) {
if ($this->formatter) {
return $this->formatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE);
}
return null;
}
return $this->options['currency_code'];
}
示例2: getRules
private function getRules($locale, $type)
{
$formatter = new \NumberFormatter($locale, $type);
$rules = [];
$rawRules = explode(';', trim($formatter->getTextAttribute(\NumberFormatter::PUBLIC_RULESETS), ';'));
$default = $formatter->getTextAttribute(\NumberFormatter::DEFAULT_RULESET);
foreach ($rawRules as $rule) {
$rules[$rule] = $rule === $default;
}
return $rules;
}
示例3: 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);
}
if ($this->maxFractionDigits !== null) {
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $this->maxFractionDigits);
}
$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 '';
}
示例4: getTextAttribute
/**
* @inheritdoc
*/
public function getTextAttribute($attr)
{
return isset($this->attributes[$attr]) ? $this->attributes[$attr] : parent::getTextAttribute($attr);
}
示例5: testGetTextAttribute
public function testGetTextAttribute()
{
$this->skipIfIntlExtensionIsNotLoaded();
$intlDecimalFormatter = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
$intlCurrencyFormatter = new \NumberFormatter('en', \NumberFormatter::CURRENCY);
$stubDecimalFormatter = $this->getStubFormatterWithDecimalStyle();
$stubCurrencyFormatter = $this->getStubFormatterWithCurrencyStyle();
for ($i = 0; $i <= 5; $i++) {
$this->assertSame($stubDecimalFormatter->getTextAttribute($i), $intlDecimalFormatter->getTextAttribute($i), $i);
$this->assertSame($stubCurrencyFormatter->getTextAttribute($i), $intlCurrencyFormatter->getTextAttribute($i), 'fooo ' . $i);
}
}
示例6: getCurrCode
public function getCurrCode($locale = NULL)
{
if ($locale === NULL) {
$locale = $this->locale;
}
if (extension_loaded('intl')) {
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
return $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
}
}
示例7: nReal
/**
* Mostra o Valor no real Formatado
* @param float $number
* @param boolean $fixed
* @param boolean $symbol
* @param integer $decimals
* @return string
*/
public static function nReal($number, $decimals = 2, $symbol = true, $fixed = true)
{
if (is_null($number) || empty(self::onlyNumbers($number))) {
return '';
}
$formater = new \NumberFormatter("pt-BR", \NumberFormatter::CURRENCY);
$formater->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $fixed ? $decimals : 1);
if ($decimals === false) {
$decimals = 2;
preg_match_all('/[0-9][^0-9]([0-9]+)/', $number, $matches);
if (!empty($matches[1])) {
$decimals = strlen(rtrim($matches[1][0], 0));
}
}
$formater->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
if (!$symbol) {
$pattern = preg_replace("/[¤]/", '', $formater->getPattern());
$formater->setPattern($pattern);
} else {
// ESPAÇO DEPOIS DO SIMBOLO
$pattern = str_replace("¤", "¤ ", $formater->getPattern());
$formater->setPattern($pattern);
}
return $formater->formatCurrency($number, $formater->getTextAttribute(\NumberFormatter::CURRENCY_CODE));
}