Format Fancy Number (##st, ##nd, ##rd, ##th)
This function adds st, nd, rd, or th to the end of a string of numbers based on what the number is. For example, the following code can produce the following output, "Thursday, November 23rd, 2000" : Format(Date, "dddd, mmmm ") & FormatFancyNumber(Day(Date)) & ", " & Year(Date)
Inputs
All this function needs is an integer number in string format.
Returns
It returns the number in string format with st, nd, rd, or th added to the end as needed.
Side Effects
The code currently only works with integer size numbers. This should be easy to change though considering the size of code.
Rate Format Fancy Number (##st, ##nd, ##rd, ##th)
(3(3 Vote))
Public Function FormatFancyNumber(ByVal sNumber As String) As String
Dim iTemp As Integer
iTemp = Int(sNumber)
If 4 < iTemp And iTemp < 20 Then
FormatFancyNumber = sNumber & "th"
Else
Select Case iTemp Mod 10
Case 1
FormatFancyNumber = sNumber & "st"
Case 2
FormatFancyNumber = sNumber & "nd"
Case 3
FormatFancyNumber = sNumber & "rd"
Case Else
FormatFancyNumber = sNumber & "th"
End Select
End If
End Function
Format Fancy Number (##st, ##nd, ##rd, ##th) Comments
No comments yet — be the first to post one!
Post a Comment