Win a copy of Head First Go this week in the Go 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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: 63478
207
  • 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.

 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!