Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

499
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda