NumberFormatter::parse

numfmt_parse

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

NumberFormatter::parse -- numfmt_parseAnaliza un número

Descripción

Estilo orientado a objetos

publicNumberFormatter::parse(string$value, int$type = ?, int&$position = ?): mixed

Estilo por procedimientos

numfmt_parse(
    NumberFormatter$fmt,
    string$value,
    int$type = ?,
    int&$position = ?
): mixed

Pasar de un string a un número usando las reglas actuales de formateo.

Parámetros

fmt

NumberFormatter object.

type

El tipo de formateo a usar. Por defecto, se utiliza NumberFormatter::TYPE_DOUBLE.

position

Lugar del string a partir del cual se debe convertir. Al regresar, este valor contendrá el lugar en el que la conversión ha finalizado.

Valores devueltos

El valor del número convertido o false en caso de error.

Ejemplos

Ejemplo #1 Ejemplo de numfmt_parse()

<?php
$fmt
= numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo
numfmt_parse($fmt, $num)."\n";
echo
numfmt_parse($fmt, $num, NumberFormatter::TYPE_INT32)."\n";
?>

Ejemplo #2 Ejemplo O.O.

<?php
$fmt
= new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo
$fmt->parse($num)."\n";
echo
$fmt->parse($num, NumberFormatter::TYPE_INT32)."\n";
?>

El resultado del ejemplo sería:

1234567.891 1234567

Ver también

To Top