Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

491
Vistas
Is this a bug with PHP's NumberFormatter::SPELLOUT? Can it be made smarter/less strict?

Example code:

function number_from_spelledout_number($number_string)
{
    $a = new \NumberFormatter('en_US', \NumberFormatter::SPELLOUT);
    return $a->parse($number_string);
} 

var_dump(number_from_spelledout_number('one'));
var_dump(number_from_spelledout_number('two'));
var_dump(number_from_spelledout_number('twenty'));
var_dump(number_from_spelledout_number('twenty-one'));
var_dump(number_from_spelledout_number('twenty one'));
var_dump(number_from_spelledout_number('twentyone'));

Expected/desired output:

float(1)
float(2)
float(20)
float(21)
float(21)
float(21)

Actual output:

float(1)
float(2)
float(20)
float(21)
float(2001)
float(20)

As you can see, it only understands specifically the format "twenty-one" to mean "21"; both "twenty one" and "twentyone" confuse it into the wrong numbers.

While I would personally always type "twenty-one", I know people: they never type the way you would want them to. They will very obviously type "twenty one" and "twentyone" and many other variations, and that's assuming they even get the spelling right. I would not be surprised to get input such as "twenti too" or "tve enty 2" etc. in "the wild". And then this thing breaks.

Is it possible to (easily) make this more intelligent/solid/less strict somehow?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda