-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspan_num.rb
113 lines (73 loc) · 2 KB
/
span_num.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
def spanish_number numero
if numero < 0
return 'menos ' + (spanish_number (-1)*numero)
end
if numero == 0
return 'cero'
end
if numero == 1000
return 'mil'
end
#if numero >1000 & numero
num_string = ''
unos = ['uno', 'dos', 'tres', 'cuatro', 'cinco', 'seis', 'siete', 'ocho', 'nueve']
diezes = ['diez', 'veinte', 'treinta', 'cuarenta', 'cincuenta', 'sesenta', 'setenta', 'ochenta', 'noventa']
teenager = ['once', 'doce', 'trece', 'catorce', 'quince', 'dieciseis', 'diecisiete', 'dieciocho', 'diecinueve']
cientos = ['ciento', 'doscientos', 'trescientos', 'cuatrocientos', 'quinientos', 'seiscientos', 'sietecientos', 'ochocientos', 'nuevecientos']
if numero < 1000
c = numero/100%10 #cientos
d = numero/10%10 #diezes
u = numero%10 #unos
#if c==1 && d=0 && u=0
# num_string = 'cien'
#end
if c>0 && c<10
num_string = cientos[c-1] + ' '+ num_string
end
if c==1 && d==0 && u==0
num_string = 'cien' # muss ggf. korrigiert werden wenn mil dazukommen
end
if d==1 && u>0
num_string = num_string + teenager[u-1]
else
if d>0
num_string = num_string + diezes[d-1]
end
if u>0 && d>1
num_string = num_string + ' y ' + unos[u-1]
elsif u>0 && d<1
num_string = num_string + unos[u-1]
end
end
return num_string
end
# if m==1
# num_string = 'mil '+ num_string
#elsif m>1 && m <10
#num_string = unos[m-1] + ' mil ' + num_string
#end
valor = ['', 'mil', 'millones', 'millares']
v=0
while numero>0
n = numero%1000
if n>0
num_string = (spanish_number n) +' ' + valor[v] +' '+ num_string
end
v = v+1
numero = numero/1000
end
return num_string
end
puts spanish_number 198
puts spanish_number 100
puts spanish_number 72
puts spanish_number 1679
puts spanish_number 3619
puts spanish_number 4
puts spanish_number 798
puts spanish_number 15567
puts spanish_number 1000
puts spanish_number 121450
puts spanish_number 8761570
puts spanish_number 91760
puts spanish_number -7865480