Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a VB.NET function to format a number as an Ordinal

Is there a built in VB.NET function to format a number as an Ordinal or do I have to write my own?

There isn't in C# so I'm thinking there isn't :(

like image 635
David A Gibson Avatar asked Dec 09 '22 22:12

David A Gibson


1 Answers

Already answered in Ordinals in C# Search is your friend . . .

Basically "No, there is no method provided in the framework", but there are good answers about how to do it.

EDIT

Apologies to whom ever thought I deserved the downvote, I should have translated the C# to vb.net.

Public Function AddOrdinal(ByVal num As Integer) as String
    Select Case (num Mod 100)
        Case 11 To 13
            Return num.ToString() & "th"
    End Select
    Select Case num Mod 10
        Case 1
            Return num.ToString() & "st"
        Case 2
            Return num.ToString() & "nd"
        Case 3
            Return num.ToString() & "rd"
        Case Else
            Return num.ToString() & "th"
    End Select
End Function
like image 141
Binary Worrier Avatar answered Mar 04 '23 01:03

Binary Worrier