PHP 8.5.0 Alpha 1 available for testing

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_attributeLee un atributo textual

Descripción

Estilo orientado a objetos

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

Estilo procedimental

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

Lee un atributo textual asociado a un formateador. Un ejemplo de atributo textual es el sufijo para los números positivos. Si el formateador no comprende este atributo, se produce un error U_UNSUPPORTED_ERROR. Los formateadores de reglas comprenden únicamente NumberFormatter::DEFAULT_RULESET y NumberFormatter::PUBLIC_RULESETS.

Parámetros

formatter

El objeto NumberFormatter.

attribute

El identificador del atributo: una de las constantes de atributo textual.

Valores devueltos

Devuelve el valor del atributo en caso de éxito, y false en caso contrario.

Ejemplos

Ejemplo #1 Ejemplo con numfmt_get_text_attribute(), Estilo procedimental

<?php
$fmt
= numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo
"Prefijo : ".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
"Prefijo : ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo
numfmt_format($fmt, -1234567.891234567890000)."\n";
?>

Ejemplo #2 Ejemplo con numfmt_get_text_attribute(), estilo POO

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

El ejemplo anterior mostrará :

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

Ver también

add a note

User Contributed Notes

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