You can try porting this VB code to C#
It is designed to handle numbers larger than longs so it is using
floating points, hence the MyRound function. You'll need to fix that
bit up yourself, just make sure lResult is the rounded down result of
"vlNumber / 100...".
Good luck.
(BTW this is recursive)
Private Function NumberToWord(ByVal vlNumber#) As String
Dim lResult#
Dim sWord$
ReDim One(0 To 19) As String, Ten(2 To 9) As String
lResult = MyRound(vlNumber / 1000000000, 1, "D") ' How many Billions
are there ?
vlNumber = vlNumber - lResult * 1000000000 ' remove Billions
If lResult > 0 Then
sWord$ = sWord & flNumberToWord(lResult) & " BILLION " ' call
flNumberToWord to convert the no.
End If ' of
Billions to text
lResult = MyRound(vlNumber / 1000000, 1, "D") ' Millions ?
vlNumber = vlNumber - lResult * 1000000
If lResult > 0 Then
sWord$ = sWord & flNumberToWord(lResult) & " MILLION "
End If
lResult = MyRound(vlNumber / 1000, 1, "D") ' Thousands ?
vlNumber = vlNumber - lResult * 1000
If lResult > 0 Then
sWord$ = sWord & flNumberToWord(lResult) & " THOUSAND "
End If
lResult = MyRound(vlNumber / 100, 1, "D") ' Hundreds ?
vlNumber = vlNumber - lResult * 100
If lResult > 0 Then
sWord$ = sWord & flNumberToWord(lResult) & " HUNDRED "
End If
One(0) = ""
One(1) = "ONE"
One(2) = "TWO"
One(3) = "THREE"
One(4) = "FOUR"
One(5) = "FIVE"
One(6) = "SIX"
One(7) = "SEVEN"
One(8) = "EIGHT"
One(9) = "NINE"
One(10) = "TEN"
One(11) = "ELEVEN"
One(12) = "TWELVE"
One(13) = "THIRTEEN"
One(14) = "FOURTEEN"
One(15) = "FIFTEEN"
One(16) = "SIXTEEN"
One(17) = "SEVENTEEN"
One(18) = "EIGHTEEN"
One(19) = "NINETEEN"
Ten(2) = "TWENTY"
Ten(3) = "THIRTY"
Ten(4) = "FOURTY"
Ten(5) = "FIFTY"
Ten(6) = "SIXTY"
Ten(7) = "SEVENTY"
Ten(8) = "EIGHTY"
Ten(9) = "NINETY"
lResult = MyRound(vlNumber / 10, 1, "D") ' Tens ?
If lResult >= 2 Then ' if remaining is 20 or greater then there are
still units remaining (0 - 9)
vlNumber = vlNumber - lResult * 10
sWord$ = sWord & Ten(lResult) & " " & flNumberToWord(vlNumber)
Else ' 0 - 19 (these can't be
broken down)
NumberToWord = Trim$(sWord & One(vlNumber))
Exit Function
End If
NumberToWord = Trim$(sWord)
Exit Function
End Function