Format numbers e.g. 1 -> 1st, 12 -> 12th, 23 ->23rd

  • Thread starter Thread starter lee atkinson
  • Start date Start date
L

lee atkinson

Hi

Is there anything in the framework that will format a number's 'order'
suffix - to make it the Nth

Regards

Lee
 
Hi Lee,

There is nothing that will automatically add st nd rd th to the number, but you should be able to do it yourself with a simple algorithm. Just check the last digit or in case the second last is 1 use th.
 
There is nothing that will automatically add st nd rd th to the number, but
you should be able to do it yourself with a simple algorithm. Just check
the last digit or in case the second last is 1 use th.
And hope you will never have to localize you application.
Puting in the code such a thing is very bad internationalization practice.
 
Hi Lee,

There is nothing that will automatically add st nd rd th to the number, but you should be able to do it yourself with a simple algorithm. Just check the last digit or in case the second last is 1 use th.

Try this simple (VB) routine:

Public Function OrdinalSuffix(ByVal ThisInteger As Integer) As String
If (ThisInteger > 4) And (ThisInteger < 20) Then
Return "th"
End If
Select Case CDbl(ThisInteger) Mod 10
Case 1
Return "st"
Case 2
Return "nd"
Case 3
Return "rd"
Case Else
Return "th"
End Select
End Function
 
Hi - thanks for your replies

It was thinking about internationalization that I was wondering if
there was anything in the Framework that would so this - I didn't want
to hardcode st, nd, th, etc into my code, recgonising that other
cultures do not use these.

Lee
 
Hi - thanks for your replies

It was thinking about internationalization that I was wondering if
there was anything in the Framework that would so this - I didn't want
to hardcode st, nd, th, etc into my code, recgonising that other
cultures do not use these.

Lee

There is nothing pre-packaged in the framework that will spit out
ordinal numbers for any culture.
(Ordinal: first, second, third, etc., as opposed to Cardinal: one,
two, three, and so on)

This is a very difficult topic, as BYTE put it once: "There is NO
magic bullet", (people make livings out of it.)

Out of interest, you may want to look at:
http://www-306.ibm.com/software/globalization/topics/locales/numeric_intro.jsp
http://www.whizkidtech.redprince.net/ISO-8859-2/sk.html
http://www.concentric.net/~rtgillam/pubs/NumberSpellout.htm

The way I deal with this problem, is to have a function to which you
feed a decimal, and a culture string, and let a Select or Switch
statement do each culture individually.
But I'm not about to let this loose for free!
 
Back
Top