フィルターのクリア

Fun Question but Confusing! Convert Number to English phrase

1 回表示 (過去 30 日間)
Sang Yeob Kim
Sang Yeob Kim 2014 年 12 月 4 日
コメント済み: Stephen23 2015 年 12 月 7 日
d
  1 件のコメント
Stephen23
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
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.

その他の回答 (2 件)

John D'Errico
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.

Sean de Wolski
Sean de Wolski 2014 年 12 月 4 日

カテゴリ

Help Center および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by