I recently need to format numbers as 1st, 2nd, ... 121st, ...
So I wrote these routines. Figured someone else may need them
Call Ordinal passing number and it will returns its Suffix and just the Suffix
Call FullOrdinal passing number it will return the number with the suffix
BobVal
So I wrote these routines. Figured someone else may need them
Call Ordinal passing number and it will returns its Suffix and just the Suffix
Call FullOrdinal passing number it will return the number with the suffix
B4X:
Public Sub Ordinal(Number As Int) As String
Dim Mod100 As Int = Number Mod 100
Dim Mod10 As Int = Number Mod 10
If Mod10 = 1 And Mod100 <> 11 Then
Return "st"
End If
If Mod10 = 2 And Mod100 <> 12 Then
Return "nd"
End If
If Mod10 = 3 And Mod100 <> 13 Then
Return "rd"
End If
Return "th"
End Sub
Public Sub FullOrdinal(Number As Int) As String
Dim Mod100 As Int = Number Mod 100
Dim Mod10 As Int = Number Mod 10
If Mod10 = 1 And Mod100 <> 11 Then
Return Number &"st"
End If
If Mod10 = 2 And Mod100 <> 12 Then
Return Number &"nd"
End If
If Mod10 = 3 And Mod100 <> 13 Then
Return Number &"rd"
End If
Return Number &"th"
End Sub
BobVal