-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversor.js
More file actions
86 lines (79 loc) · 1.99 KB
/
conversor.js
File metadata and controls
86 lines (79 loc) · 1.99 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
module.exports = {
converterPorExtenso: converterPorExtenso
};
function converteDe1a99(argAsInt) {
if (argAsInt < 20 && argAsInt > 10) {
return tabelaDeOnzeADezenove[argAsInt];
} else if (argAsInt < 10) {
return tabelaDeUnidades[argAsInt];
} else if (argAsInt === 10) {
return 'dez';
} else if (argAsInt % 10 == 0 && argAsInt < 100) {
return tabelaDeDezenas[argAsInt];
} else if (argAsInt > 20 && argAsInt < 100) {
return `${tabelaDeDezenas[Math.floor(argAsInt/10)*10]} e ${tabelaDeUnidades[argAsInt%10]}` ;
}
return null;
}
function converterPorExtenso(args) {
var argAsInt = parseInt(args, 10);
if (argAsInt < 100) {
return converteDe1a99(argAsInt)
}
if (argAsInt % 100 == 0) {
return tabelaDeCentenas[argAsInt];
} else {
if (argAsInt < 200) {
if (argAsInt < 110) {
return `cento e ${tabelaDeUnidades[argAsInt%10]}`;
}
return `cento e ${converteDe1a99(argAsInt%100)}`
}
return `${tabelaDeCentenas[Math.floor(argAsInt/100)*100]} e ${converteDe1a99(argAsInt%100)}`;
}
}
var tabelaDeUnidades = {
'0': 'zero',
'1': 'um',
'2': 'dois',
'3': 'três',
'4': 'quatro',
'5': 'cinco',
'6': 'seis',
'7': 'sete',
'8': 'oito',
'9': 'nove',
};
var tabelaDeOnzeADezenove = {
'11': 'onze',
'12': 'doze',
'13': 'treze',
'14': 'quatorze',
'15': 'quinze',
'16': 'dezesseis',
'17': 'dezessete',
'18': 'dezoito',
'19': 'dezenove'
};
var tabelaDeDezenas = {
'10': 'dez',
'20': 'vinte',
'30': 'trinta',
'40': 'quarenta',
'50': 'cinquenta',
'60': 'sessenta',
'70': 'setenta',
'80': 'oitenta',
'90': 'noventa'
};
var tabelaDeCentenas = {
'100': 'cem',
'200': 'duzentos',
'300': 'trezentos',
'400': 'quatrocentos',
'500': 'quinhentos',
'600': 'seiscentos',
'700': 'setecentos',
'800': 'oitocentos',
'900': 'novecentos'
};