Fun Question but Confusing! Convert Number to English phrase
1 次查看(过去 30 天)
显示 更早的评论
d
1 个评论
Stephen23
2015-12-7
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'
采纳的回答
Star Strider
2014-12-4
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.
0 个评论
更多回答(2 个)
John D'Errico
2014-12-4
编辑:John D'Errico
2014-12-4
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!