This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
Sheriff
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: 59786
188
  • 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
Boost this thread!