PHP 8.5.0 Alpha 1 available for testing

NumberFormatter::setTextAttribute

numfmt_set_text_attribute

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

NumberFormatter::setTextAttribute -- numfmt_set_text_attributeModifica un atributo de texto

Descripción

Estilo orientado a objetos

public NumberFormatter::setTextAttribute(int $attribute, string $value): bool

Estilo procedimental

numfmt_set_text_attribute(NumberFormatter $formatter, int $attribute, string $value): bool

Modifica el atributo de texto asociado al formateador. Un ejemplo de atributo de texto es el sufijo de los números positivos. Si el formateador no comprende el atributo, se produce un error U_UNSUPPORTED_ERROR. Los formateadores basados en reglas solo comprenden NumberFormatter::DEFAULT_RULESET y NumberFormatter::PUBLIC_RULESETS.

Parámetros

formatter

Un objeto NumberFormatter.

attribute

Un especificador de atributo: una de las constantes de atributo de texto.

value

El valor del atributo de texto.

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Ejemplos

Ejemplo #1 Ejemplo con numfmt_set_text_attribute(), Estilo procedimental

<?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";
?>

Ejemplo #2 Ejemplo con numfmt_set_text_attribute(), Estilo procedimental

<?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";
?>

El ejemplo anterior mostrará :

Prefix: -
-1.234.567,891
Prefix: 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