-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathword_numbers.spd
More file actions
executable file
·51 lines (37 loc) · 1.43 KB
/
word_numbers.spd
File metadata and controls
executable file
·51 lines (37 loc) · 1.43 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
#!/usr/local/bin/spd
main (|int| Count = 100)
for Count
|| num = 4MB()
"$num --> ${num.words}"
function int64.Words (|string|)
|| Negate = self < 0
self = -self
if !self
return "Zero"
|| Units = " one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen" / ' '
|| Tens = " twenty thirty forty fifty sixty seventy eighty ninety" / ' '
|| Multiplier = " thousand million billion trillion quadrillion quintrillion" / ' '
|| Group = 0
while self
|| Value = self mod 1000 // Process number in group of 1000s
Self = self / 1000
if value
|| temp = ""
|| word = units[value / 100] // Handle 3 digit number
(value mod= 100)
temp = word + " hundred "
temp += "and " * (value > 0)
word = tens[value / 10] // Handle 2 digit number
if word
(value mod= 10)
temp += word + " "
word = units[value] // Handle unit number
if word
temp += word + " "
temp += multiplier[group] + " " // Add the multiplier according to the group
rz = temp + rz // Add this group result to overall result
group++
rz = "Negative "*Negate + rz
rz = rz.trim
function int.Words (|string|)
return self|int64|.words