File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Locales and Ordinal values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Locales and Ordinal values" Watch "Locales and Ordinal values" New topic
Author

Locales and Ordinal values

Alan Davey
Greenhorn

Joined: Aug 03, 2006
Posts: 3
Hi,

Are there any methods built-in to java where I can pass in an integer value and get an ordinal value (i.e. 1st, 2nd, 3rd, etc.) in return? I'm looking for something that will work with the current locale, much like number formats will return either a decimal or comma seperators for numbers based on the current locale.

I've searched here and on google, but so far I haven't had much luck finding what I want.

Any help would be greatly appreciated.

Thanks.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

There is no built-in method in the standard API for this, so you would have to write something yourself, or find it somewhere else.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Aaron Harp
Greenhorn

Joined: Jul 12, 2006
Posts: 8
Here is a method I wrote to take an integer and return its ordinal equivalent. Hope it helps.

Aaron Harp
Greenhorn

Joined: Jul 12, 2006
Posts: 8
It doesn't take locales into account but that wouldn't be too difficult.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36468
    
  16
. . . That is a good way to convert cardinal numbers to ordinal, but what about 11th 12th and 13th? CR
Aaron Harp
Greenhorn

Joined: Jul 12, 2006
Posts: 8
Oops, didn't think about that.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Locales and Ordinal values
 
Similar Threads
NaN
Enums in a map
switch on a string?
Trouble formatting a Date based on the User's Locale
Get Enum By Ordinal