4.0

4.0 | 1 rating Rate this file 0 Downloads (last 30 days) File Size: 10.09 KB File ID: #13577

num2english

by Dave Kellow

 

08 Jan 2007 (Updated 08 Jan 2007)

Converts real numbers to plain english

| Watch this File

File Information
Description

NUM2ENGLISH Convert numbers to plain english.
T = num2english(X) returns the plain english representation of the
number X. If X is a vector, it returns a character array with each
number in a different row.
 
T = num2english(X,'year') returns a string sounding more like a year,
for instance num2english(1984,'year') will return 'nineteen
eighty-four'. If the third digit is a zero it will return 'oh', so
num2english(1706,'year') returns 'seventeen oh-six'.
 
T = num2english(X,'th') returns first, second, third etc. instead of
one two three.
 
T = num2english(X,'example') returns a display of the various aspects
of the function.

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
08 Jan 2007 John D'Errico

In general, this did ok. A few things could be improved. I'd have liked to see an H1 line. Lookfor needs that to work properly.

I know that it says this converts numbers to english. But if it does not work for complex numbers, then it should generate an error message, not a wildly incorrect result.

num2english(1+sqrt(-1))
ans =
one thousand

It also does not seem to handle early years well.

num2english(21,'year')
??? Undefined function or variable "engy".

Error in ==> num2english at 209
        engy = strrep(engy,'zero','oh-oh');

Have you ever had a "bad" year? This will pick you up:

num2english(-1,'year')
??? Error using ==> num2english
No such thing as a negative year.

8-)

And its rather picky about the second argument. For example, it will not accept 'Year' in place of 'year'.

I wanted to rate this about a 3.5 because of the items listed above, but its a neat function, so I rounded up. I'd happily raise that rating.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
strings Dave Kellow 22 Oct 2008 08:55:41
text numerics english translate Dave Kellow 22 Oct 2008 08:55:41

Contact us at files@mathworks.com