Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Locales and Ordinal values  RSS feed

 
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.
 
Java Cowboy
Posts: 16084
88
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.
 
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.
 
Marshal
Posts: 61756
193
  • 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.

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!