Borrar filtros
Borrar filtros

Fun Question but Confusing! Convert Number to English phrase

1 visualización (últimos 30 días)
d
  1 comentario
Stephen23
Stephen23 el 7 de Dic. de 2015
Very easily using my FEX submission num2words:
Easy to use, plus options for customizing the format, case, scale, sig-figs, etc:
>> num2words(0)
ans = 'zero'
>> num2words(1024)
ans = 'one thousand and twenty-four'
>> num2words(-1024)
ans = 'negative one thousand and twenty-four'
>> num2words(1024, 'pos',true, 'case','title', 'hyphen',false)
ans = 'Positive One Thousand and Twenty Four'
>> num2words(1024, struct('type','ordinal', 'case','sentence'))
ans = 'One thousand and twenty-fourth'
>> num2words(1024, 'and',false, 'order',1) % round to the tens.
ans = 'one thousand twenty'

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 4 de Dic. de 2014
I would approach it this way:
nc = {'one' 'two' 'three' 'ten' 'fifteen' 'twenty'};
n = 23;
out = [nc{6} '-' nc{3}]
You will have to create your own full cell array and figure out how to parse the number and do the necessary cell array referencing, but this should get you started on one way to do it.

Más respuestas (2)

John D'Errico
John D'Errico el 4 de Dic. de 2014
Editada: John D'Errico el 4 de Dic. de 2014
I'd use vpi . It is on the file exchange. It has a nice toy in it that will convert any integer into valid english text, representing that number.
vpi2english(vpi('112242347947688988364501324523423523445'))
ans =
one hundred twelve undecillion, two hundred forty two decillion, three hundred forty seven nonillion, nine hundred forty seven octillion, six hundred eighty eight septillion, nine hundred eighty eight sextillion, three hundred sixty four quintillion, five hundred one quadrillion, three hundred twenty four trillion, five hundred twenty three billion, four hundred twenty three million, five hundred twenty three thousand, four hundred forty five
There are limits of course. I think I gave up at 10^306-1 as the largest number it would convert, mainly because I only found names up to that point when I looked online.
If you insist on doing it yourself, you can. Star gave you a simple answer that is quite valid and quite doable.

Sean de Wolski
Sean de Wolski el 4 de Dic. de 2014

Categorías

Más información sobre Call Web Services from MATLAB Using HTTP en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by