
Signature
Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com
On Jan 14, 9:59 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Sun, 13 Jan 2008 19:50:48 -0800 (PST), KelvinWon...@gmail.com
> wrote, quoted or indirectly quoted someone who said :
[quoted text clipped - 18 lines]
> Roedy Green, Canadian Mind Products
> The Java Glossary,http://mindprod.com
Interesting, I've never heard of the 11st, 12nd or 13rd...
It's much better (and easier) to just do this:
private static String getSuffix(int i) {
switch (i) {
case 1:
case 21:
case 31:
return "st";
case 2:
case 22:
return "nd";
case 3:
case 23:
return "rd";
default:
return "th";
}
}
Roedy Green - 31 Jan 2008 10:37 GMT
On Wed, 30 Jan 2008 16:52:24 -0800 (PST),
armwrestlingwithchasanddave@hotmail.com wrote, quoted or indirectly
quoted someone who said :
>It's much better (and easier) to just do this:
> private static String getSuffix(int i) {
[quoted text clipped - 13 lines]
> }
> }
here is my corrected version
/**
* produces an ordinal "th" suffix string for given number.
* @param number value you want the ordinal suffix for:
* @return corresponding ordinal suffix, i.e. "st", "nd", "rd", or
"th"
*/
String ordinalSuffix ( int value )
{
value = Math.abs( value );
final int lastDigit = value % 10;
final int last2Digits = value % 100;
switch ( lastDigit )
{
case 1 :
return last2digits == 11 ? "th" : "st";
case 2:
return last2digits == 12 ? "th" : "nd";
case 3:
return last2digits == 13 ? "th" : "rd";
default:
return "th";
}
}

Signature
Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com