Code covered by the BSD License  

Highlights from
ORDNUMSTR

Be the first to rate this file! 0 Downloads (last 30 days) File Size: 1.81 KB File ID: #20851
image thumbnail

ORDNUMSTR

by Richie Cotton

 

25 Jul 2008 (Updated 31 Jul 2008)

Makes an ordinal numeral string from a number, e.g. 3 becomes 3rd.

| Watch this File

File Information
Description

Makes an ordinal numeral string from a number, e.g. 3 becomes 3rd.

ORDNUMSTR(NUMBER) accepts a floating point number and appends a suitable suffix to form the ordinal numeral for the input (in English).

ORDNUMSTR(NUMBER, 0) simply returns the suffix.

The correct suffix in the case of non-integers is likely to stir up as much heated debate as 'what is best: emacs or vi?'. This function takes the last digit as the suffix generator, so that 81.3 becomes 81.3rd. The alternative would be to use the last digit before the decimal place to give 81.3st, but in my mind "threest" doesn't sound good. If you prefer the latter, then replace line 43 with line 44 and line 58 with line 59. Linguistic pendants may also note that in the case of non-integers, the numbers aren't really ordinal.

Update: Integers ending 11, 12 or 13 are now correctly given a 'th' suffix.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Number to Ordinal String Converter

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
25 Jul 2008 John D'Errico

These seem a bit strange.

ordnumstr(11)
ans =
11st

ordnumstr(12)
ans =
12nd

ordnumstr(13)
ans =
13rd

25 Jul 2008 John D'Errico

I should have added this: lots of good examples, plus good, complete help, etc.

Please login to add a comment or rating.
Updates
31 Jul 2008

Bug fix: 1inputs of 11, 12 and 13 now handled correctly.

31 Jul 2008

Bug fix: Input of integer ending 11, 12 or 13 now (really!) correctly handled.

Tag Activity for this File
Tag Applied By Date/Time
ordinal numeral Richie Cotton 22 Oct 2008 10:11:53
string convertor Richie Cotton 22 Oct 2008 10:11:53
utilities Richie Cotton 22 Oct 2008 10:11:53
numeral string Richie Cotton 22 Oct 2008 10:11:53

Contact us at files@mathworks.com