-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnum2words
More file actions
85 lines (67 loc) · 2.21 KB
/
Copy pathnum2words
File metadata and controls
85 lines (67 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
' works in excel 2013 add a module and paste the code below use like an excel function
Function num2words(amount As Double) As String
Dim paise As Double
Dim rupees As Double
Dim paiseinwords As String
rupees = amount \ 1
paise = amount - rupees
paiseinwords = ""
If paise > 0 Then
paiseinwords = " and Paise" + getparts(paise * 100)
End If
num2words = "Rupees" + getparts(rupees) + paiseinwords + " only"
num2words = Replace(num2words, " ", " ")
End Function
Private Function getparts(amount As Double) As String
Dim finalval As String
Dim findmod As Double
Dim findcount As Double
finalval = ""
If amount >= 10000000 Then
findmod = amount Mod 10000000
findcount = amount \ 10000000
finalval = finalval + getparts(findcount) + pluralize(" Crore", findcount) + getparts(findmod)
GoSub returnval
End If
If amount >= 100000 Then
findmod = amount Mod 100000
findcount = amount \ 100000
finalval = finalval + getparts(findcount) + pluralize(" Lac", findcount) + getparts(findmod)
GoSub returnval
End If
If amount >= 1000 Then
findmod = amount Mod 1000
findcount = amount \ 1000
finalval = finalval + getparts(findcount) + " Thousand" + getparts(findmod)
GoSub returnval
End If
If amount >= 100 Then
findmod = amount Mod 100
findcount = amount \ 100
finalval = finalval + getparts(findcount) + " Hundred" + getparts(findmod)
GoSub returnval
End If
If amount >= 20 Then
findmod = amount Mod 10
findcount = amount \ 10
finalval = finalval + Choose(findcount, "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety") + getparts(findmod)
GoSub returnval
End If
If amount >= 10 Then
findmod = amount Mod 10
findcount = amount \ 10
finalval = finalval + Choose(findcount, "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen")
GoSub returnval
End If
If amount < 10 Then
If amount = 0 Then GoSub returnval
findmod = amount
finalval = finalval + Choose(amount, "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine")
GoSub returnval
End If
returnval:
getparts = " " + finalval
End Function
Function pluralize(val As String, count As Double)
If count > 1 Then pluralize = val + "s" Else pluralize = val
End Function