How to resolve the algorithm Spelling of ordinal numbers step by step in the VBA programming language
How to resolve the algorithm Spelling of ordinal numbers step by step in the VBA programming language
Table of Contents
Problem Statement
Ordinal numbers (as used in this Rosetta Code task), are numbers that describe the position of something in a list. It is this context that ordinal numbers will be used, using an English-spelled name of an ordinal number.
The ordinal numbers are (at least, one form of them): sometimes expressed as:
For this task, the following (English-spelled form) will be used:
Furthermore, the short scale numbering system (i.e. 2,000,000,000 is two billion) will be used here. wp:Long and short scales 2,000,000,000 is two billion, not two milliard.
Write a driver and a function (subroutine/routine ···) that returns the English-spelled ordinal version of a specified number (a positive integer). Optionally, try to support as many forms of an integer that can be expressed: 123 00123.0 1.23e2 all are forms of the same integer. Show all output here.
Use (at least) the test cases of:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Spelling of ordinal numbers step by step in the VBA programming language
Source code in the vba programming language
Private Function ordinal(s As String) As String
Dim irregs As New Collection
irregs.Add "first", "one"
irregs.Add "second", "two"
irregs.Add "third", "three"
irregs.Add "fifth", "five"
irregs.Add "eighth", "eight"
irregs.Add "ninth", "nine"
irregs.Add "twelfth", "twelve"
Dim i As Integer
For i = Len(s) To 1 Step -1
ch = Mid(s, i, 1)
If ch = " " Or ch = "-" Then Exit For
Next i
On Error GoTo 1
ord = irregs(Right(s, Len(s) - i))
ordinal = Left(s, i) & ord
Exit Function
1:
If Right(s, 1) = "y" Then
s = Left(s, Len(s) - 1) & "ieth"
Else
s = s & "th"
End If
ordinal = s
End Function
Public Sub ordinals()
tests = [{1, 2, 3, 4, 5, 11, 65, 100, 101, 272, 23456, 8007006005004003, 123, 00123.0, 1.23E2}]
init
For i = 1 To UBound(tests)
Debug.Print ordinal(spell(tests(i)))
Next i
End Sub
You may also check:How to resolve the algorithm Percentage difference between images step by step in the Wren programming language
You may also check:How to resolve the algorithm Reverse words in a string step by step in the Elixir programming language
You may also check:How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Boolean values step by step in the KonsolScript programming language
You may also check:How to resolve the algorithm Entropy step by step in the Seed7 programming language