Convert number to word


This code converts number to word.The input should be supplied in the range 1 to 99.

Convert number to word




Dim n As Long
'The output is saved in variable strOutPut.
Dim strOutPut As String = ""
Dim l, r As Integer


'Here 74 is considred as input.You may change as
'per your requirement.
n = 74
'Get the floor value
l = Math.Floor(n / 10)
r = n Mod 10
If l = 1 Then
'For returning number from 10 to 19
Select Case r
Case 0
strOutPut = strOutPut & " Ten"
Case 1
strOutPut = strOutPut & " Eleven"
Case 2
strOutPut = strOutPut & " Twelve"
Case 3
strOutPut = strOutPut & " Thirteen"
Case 4
strOutPut = strOutPut & " Fourteen"
Case 5
strOutPut = strOutPut & " Fifteen"
Case 6
strOutPut = strOutPut & " Sixteen"
Case 7
strOutPut = strOutPut & " Seventeen"
Case 8
strOutPut = strOutPut & " Eighteen"
Case 9
strOutPut = strOutPut & " Nineteen"
End Select
Else
'For returning the number in multiple of 10.
Select Case l
Case 2
strOutPut = strOutPut & " Twenty"
Case 3
strOutPut = strOutPut & " Thirty"
Case 4
strOutPut = strOutPut & " Forty"
Case 5
strOutPut = strOutPut & " Fifty"
Case 6
strOutPut = strOutPut & " Sixty"
Case 7
strOutPut = strOutPut & " Seventy"
Case 8
strOutPut = strOutPut & " Eighty"
Case 9
strOutPut = strOutPut & " Ninety"
End Select
'For returning single digit number.
Select Case r
Case 1
strOutPut = strOutPut & " One"
Case 2
strOutPut = strOutPut & " Two"
Case 3
strOutPut = strOutPut & " Three"
Case 4
strOutPut = strOutPut & " Four"
Case 5
strOutPut = strOutPut & " Five"
Case 6
strOutPut = strOutPut & " Six"
Case 7
strOutPut = strOutPut & " Seven"
Case 8
strOutPut = strOutPut & " Eight"
Case 9
strOutPut = strOutPut & " Nine"
End Select
End If
MessageBox.Show(strOutPut)


Comments

Author: Vikram Singh Saini28 Mar 2010 Member Level: Gold   Points : 1

Hi! Could you please provide the same code in C#?

And is it not possible to remove limitations for 1-99?

Thanks and Regards,
Vikram Singh Saini



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: