Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 358
- Office Version
- 2003 or older
- Platform
- Windows
I have a VBA code which handles number to word conversion upto Trillion.
I need modification to code such that it can handle conversion upto Duodecillion; i.e.:
One 1 1×10^0 0
Ten 10 1×10^1 1
Hundred 100 1×10^2 2
Thousand 1,000 1×10^3 3
Million 10,00,000 1×10^6 6
Billion 1,00,00,00,000 1×10^9 9
Trillion 10,00,00,00,00,000 1×10^12 12
Quadrillion 1,00,00,00,00,00,00,000 1×10^15 15
Quintillion 10,00,00,00,00,00,00,00,000 1×10^18 18
Sextillion 1,00,00,00,00,00,00,00,00,00,000 1×10^21 21
Septillion 10,00,00,00,00,00,00,00,00,00,00,000 1×10^24 24
Octillion 1,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^27 27
Nonillion 10,00,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^30 30
Decillion 1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^33 33
Undecillion 10,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^36 36
Duodecillion 1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^39 39
The VBA code is:
Function NumbersToWords(ByVal Num As Currency) As String
Dim Power_value(1 To 6) As Currency
Dim Power_name(1 To 6) As String
Dim Digits As Integer
Dim Result As String
Dim I As Integer
Power_name(1) = "Trillion": Power_value(1) = 1000000000000#
Power_name(2) = "Billion": Power_value(2) = 1000000000
Power_name(3) = "Million": Power_value(3) = 1000000
Power_name(4) = "Lakh": Power_value(4) = 100000
Power_name(5) = "Thousand": Power_value(5) = 1000
Power_name(6) = "": Power_value(6) = 1
For I = 1 To 6
If Num >= Power_value(I) Then
Digits = Int(Num / Power_value(I))
If Len(Result) > 0 Then Result = Result & " "
Result = Result & Words_1_999(Digits) & " " & Power_name(I)
Num = Num - Digits * Power_value(I)
End If
Next I
NumbersToWords = Trim$(Result)
End Function
Function Words_1_999(ByVal Num As Integer) As String
Dim Hundreds As Integer
Dim Remainder As Integer
Dim Result As String
Hundreds = Num \ 100
Remainder = Num - Hundreds * 100
If Hundreds > 0 Then
Result = Words_1_19(Hundreds) & " Hundred "
End If
If Remainder > 0 Then
Result = Result & Words_1_99(Remainder)
End If
Words_1_999 = Trim$(Result)
End Function
Function Words_1_19(ByVal Num As Integer) As String
Select Case Num
Case 1
Words_1_19 = "One"
Case 2
Words_1_19 = "Two"
Case 3
Words_1_19 = "Three"
Case 4
Words_1_19 = "Four"
Case 5
Words_1_19 = "Five"
Case 6
Words_1_19 = "Six"
Case 7
Words_1_19 = "Seven"
Case 8
Words_1_19 = "Eight"
Case 9
Words_1_19 = "Nine"
Case 10
Words_1_19 = "Ten"
Case 11
Words_1_19 = "Eleven"
Case 12
Words_1_19 = "Twelve"
Case 13
Words_1_19 = "Thirteen"
Case 14
Words_1_19 = "Fourteen"
Case 15
Words_1_19 = "Fifteen"
Case 16
Words_1_19 = "Sixteen"
Case 17
Words_1_19 = "Seventeen"
Case 18
Words_1_19 = "Eighteen"
Case 19
Words_1_19 = "Nineteen"
End Select
End Function
Function Words_1_99(ByVal Num As Integer) As String
Dim Result As String
Dim Tens As Integer
Tens = Num \ 10
If Tens <= 1 Then
Result = Result & " " & Words_1_19(Num)
Else
Select Case Tens
Case 2
Result = "Twenty"
Case 3
Result = "Thirty"
Case 4
Result = "Forty"
Case 5
Result = "Fifty"
Case 6
Result = "Sixty"
Case 7
Result = "Seventy"
Case 8
Result = "Eighty"
Case 9
Result = "Ninety"
End Select
Result = Result & " " & Words_1_19(Num - Tens * 10) & " "
End If
Words_1_99 = Trim$(Result)
End Function
I need modification to code such that it can handle conversion upto Duodecillion; i.e.:
One 1 1×10^0 0
Ten 10 1×10^1 1
Hundred 100 1×10^2 2
Thousand 1,000 1×10^3 3
Million 10,00,000 1×10^6 6
Billion 1,00,00,00,000 1×10^9 9
Trillion 10,00,00,00,00,000 1×10^12 12
Quadrillion 1,00,00,00,00,00,00,000 1×10^15 15
Quintillion 10,00,00,00,00,00,00,00,000 1×10^18 18
Sextillion 1,00,00,00,00,00,00,00,00,00,000 1×10^21 21
Septillion 10,00,00,00,00,00,00,00,00,00,00,000 1×10^24 24
Octillion 1,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^27 27
Nonillion 10,00,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^30 30
Decillion 1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^33 33
Undecillion 10,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^36 36
Duodecillion 1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000 1×10^39 39
The VBA code is:
Function NumbersToWords(ByVal Num As Currency) As String
Dim Power_value(1 To 6) As Currency
Dim Power_name(1 To 6) As String
Dim Digits As Integer
Dim Result As String
Dim I As Integer
Power_name(1) = "Trillion": Power_value(1) = 1000000000000#
Power_name(2) = "Billion": Power_value(2) = 1000000000
Power_name(3) = "Million": Power_value(3) = 1000000
Power_name(4) = "Lakh": Power_value(4) = 100000
Power_name(5) = "Thousand": Power_value(5) = 1000
Power_name(6) = "": Power_value(6) = 1
For I = 1 To 6
If Num >= Power_value(I) Then
Digits = Int(Num / Power_value(I))
If Len(Result) > 0 Then Result = Result & " "
Result = Result & Words_1_999(Digits) & " " & Power_name(I)
Num = Num - Digits * Power_value(I)
End If
Next I
NumbersToWords = Trim$(Result)
End Function
Function Words_1_999(ByVal Num As Integer) As String
Dim Hundreds As Integer
Dim Remainder As Integer
Dim Result As String
Hundreds = Num \ 100
Remainder = Num - Hundreds * 100
If Hundreds > 0 Then
Result = Words_1_19(Hundreds) & " Hundred "
End If
If Remainder > 0 Then
Result = Result & Words_1_99(Remainder)
End If
Words_1_999 = Trim$(Result)
End Function
Function Words_1_19(ByVal Num As Integer) As String
Select Case Num
Case 1
Words_1_19 = "One"
Case 2
Words_1_19 = "Two"
Case 3
Words_1_19 = "Three"
Case 4
Words_1_19 = "Four"
Case 5
Words_1_19 = "Five"
Case 6
Words_1_19 = "Six"
Case 7
Words_1_19 = "Seven"
Case 8
Words_1_19 = "Eight"
Case 9
Words_1_19 = "Nine"
Case 10
Words_1_19 = "Ten"
Case 11
Words_1_19 = "Eleven"
Case 12
Words_1_19 = "Twelve"
Case 13
Words_1_19 = "Thirteen"
Case 14
Words_1_19 = "Fourteen"
Case 15
Words_1_19 = "Fifteen"
Case 16
Words_1_19 = "Sixteen"
Case 17
Words_1_19 = "Seventeen"
Case 18
Words_1_19 = "Eighteen"
Case 19
Words_1_19 = "Nineteen"
End Select
End Function
Function Words_1_99(ByVal Num As Integer) As String
Dim Result As String
Dim Tens As Integer
Tens = Num \ 10
If Tens <= 1 Then
Result = Result & " " & Words_1_19(Num)
Else
Select Case Tens
Case 2
Result = "Twenty"
Case 3
Result = "Thirty"
Case 4
Result = "Forty"
Case 5
Result = "Fifty"
Case 6
Result = "Sixty"
Case 7
Result = "Seventy"
Case 8
Result = "Eighty"
Case 9
Result = "Ninety"
End Select
Result = Result & " " & Words_1_19(Num - Tens * 10) & " "
End If
Words_1_99 = Trim$(Result)
End Function