-
Notifications
You must be signed in to change notification settings - Fork 0
/
extenglishnum.rb
69 lines (57 loc) · 1.2 KB
/
extenglishnum.rb
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
def engnum number
if number == 0
return "zero"
end
english = ""
ones = ["one", "two", "three",
"four", "five", "six",
"seven", "eight", "nine"]
tens = ["ten", "twenty", "thirty",
"forty", "fifty", "sixty",
"seventy", "eighty", "ninety"]
teen = ["eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"]
left = number
write = left / 100
left = left % 100
if write > 0
hundreds = engnum write
english = english + hundreds + ' hundred'
if left > 0
english = english + " "
end
end
write = left / 10
left = left % 10
if write > 0
if ((write == 1) and (left > 0))
english = english + teen[left-1]
left = 0
else
english = english + tens[write-1]
end
if left > 0
english = english + "-"
end
end
write = left
left = 0
if write > 0
english = english + ones[write-1]
end
english
end
puts engnum( 0)
puts engnum( 9)
puts engnum( 10)
puts engnum( 11)
puts engnum( 17)
puts engnum( 32)
puts engnum( 88)
puts engnum( 99)
puts engnum(100)
puts engnum(101)
puts engnum(234)
puts engnum(3211)
puts engnum(999999)