Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locales and Ordinal values

 
Alan Davey
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aaron Harp
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a method I wrote to take an integer and return its ordinal equivalent. Hope it helps.

 
Aaron Harp
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't take locales into account but that wouldn't be too difficult.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . That is a good way to convert cardinal numbers to ordinal, but what about 11th 12th and 13th? CR
 
Aaron Harp
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, didn't think about that.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic