| 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
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
|
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: 32708
|
|
. . . 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.
|
 |
 |
|
|
subject: Locales and Ordinal values
|
|
|