CakeFest 2024: The Official CakePHP Conference

NumberFormatter::getTextAttribute

numfmt_get_text_attribute

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

NumberFormatter::getTextAttribute -- numfmt_get_text_attributeテキストの属性を取得する

説明

オブジェクト指向型

public NumberFormatter::getTextAttribute(int $attribute): string|false

手続き型

numfmt_get_text_attribute(NumberFormatter $formatter, int $attribute): string|false

フォーマッタに関連づけられているテキスト属性を取得します。 テキスト属性の例としては、正の数字のサフィックスなどがあります。 属性が理解できない場合は、エラー U_UNSUPPORTED_ERROR が発生します。 ルールベースのフォーマッタでは、 NumberFormatter::DEFAULT_RULESET および NumberFormatter::PUBLIC_RULESETS のみが使用できます。

パラメータ

formatter

NumberFormatter オブジェクト。

attribute

属性指定子。 テキスト属性 定数のいずれか。

戻り値

成功した場合に属性の値、あるいはエラー時に false を返します。

例1 numfmt_get_text_attribute() の例

<?php
$fmt
= numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo
"Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo
numfmt_format($fmt, -1234567.891234567890000)."\n";
numfmt_set_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo
"Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo
numfmt_format($fmt, -1234567.891234567890000)."\n";
?>

例2 オブジェクト指向の例

<?php
$fmt
= new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo
"Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo
$fmt->format(-1234567.891234567890000)."\n";
$fmt->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo
"Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo
$fmt->format(-1234567.891234567890000)."\n";
?>

上の例の出力は以下となります。

Prefix: -
-1.234.567,891
Prefix: MINUS
MINUS1.234.567,891

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top