-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs__funciones.js
More file actions
360 lines (319 loc) · 10.8 KB
/
js__funciones.js
File metadata and controls
360 lines (319 loc) · 10.8 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/**========================================================================
* ? ABOUT
* @author : Edgardo Ferreyra
* @email : ed20052006@hotmail.com
* @repo :
* @createdOn : 14/05/2022
* @description :
*========================================================================**/
/**
* description
*
* Cambio de Pantalla de Fondo
*
function Pantalla(valor) {
let error_func;
error_func = true;
const Imgg = document.getElementById("TodoIMG");
if (valor == 1) {
error_func = true;
Imgg.setAttribute("class", "Todo1");
};
if (valor == 2) {
error_func = true;
Imgg.setAttribute("class", "Todo2");
};
if (valor == 3) {
error_func = true;
Imgg.setAttribute("class", "Todo3");
};
if (error_func == false) {
Imgg.setAttribute("class", "Todo1");
};
};
*/
function randomize() {
/**
* Retorna Valor aleatorio entre [0 , 1)
*/
const rmz = Math.random();
return rmz;
}
function RnD(Min, Max, Dec) {
/**
* description
*
* Igual al Randomize pero con seleccion de rango
*/
if (Dec == null || Dec == undefined) Dec = 0;
const u = randomize();
const uu = (u * (Max - Min + 1)) + Min;
if (Dec <= 0) {
return Math.floor(uu);
} else {
return uu.toFixed(Dec);
}
}
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + '.' + '$2');
}
return x1 + x2;
}
// comparaVenta(parseInt(vOperacionValorC[0].value), oPcion, varCompraVenta.VCom, varCompraVenta.VVen)
/**
* description
*
* Usada en compra_venta.js
*
* varTipo = 1,2,3,4
* 1 Compra Alimento
* 2 Compra Tierra
* 3 Venta Alimento
* 4 Venta Tierra
*
* Retorna 0 = ok
* 1 = Mal Compra
* 2 = Mal Venta Alimento
* 3 = Mal Venta Tierra
* 4 = Mal Alimento Poblacion
*/
comparaVenta = (varOperacion, varTipo, varCompra, VarVenta, VarAlimPo) => {
let h = 0;
if (VarAlimPo == 0) {
return 4;
} else {
if (varTipo == 1) {
h = varOperacion * varCompra;
if (h > varHamurabi.Dinero) {
return 1;
} else { return 0; }
} else if (varTipo == 2) {
h = varOperacion * varCompra;
if (h > varHamurabi.Dinero) {
return 1;
} else { return 0; }
} else if (varTipo == 3) {
h = varOperacion;
if (h > varHamurabi.Alimento) {
return 2;
} else { return 0; }
} else if (varTipo == 4) {
h = varOperacion;
if (h > varHamurabi.Tierra) {
return 3;
} else { return 0; }
}
}
}
muestraRND = (Val1, Val2) => {
varGDatosC.innerHTML = `Venta : <br><b>${Val1}</b><br>
Compra : <br><b>${Val2}</b><br>`;
}
/**========================================================================
** FUNCTION NAME romanize
*? Pasar numeros a Numeros Romanos I,II,III,IV,V, etc
*@param name valor numero a pasar
*@return String
*@fuente https://www.iteramos.com/pregunta/98049/Convertir-un-numero-en-un-numero-romano-en-javaScript
*
*
*========================================================================**/
function romanize(num) {
if (isNaN(num)) return NaN;
var digits = String(+num).split(""),
key = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"],
roman = "",
i = 3;
while (i--) roman = (key[+digits.pop() + (i * 10)] || "") + roman;
return Array(+digits.join("") + 1).join("M") + roman;
}
/*============================ END OF FUNCTION ============================ romanize */
/**========================================================================
** FUNCTION NAME numeroALetras
*? Pasar numeros a Letras
*@param name valor numero a pasar
*@return String
*@fuente https://gist.github.com/alfchee/e563340276f89b22042a
*
* @example
* ```js
Modo de uso: 500,34 USD
numeroALetrasss = numeroALetras(500.34, {
plural: 'dólares estadounidenses',
singular: 'dólar estadounidense',
centPlural: 'centavos',
centSingular: 'centavo'
});
* ```
*
*========================================================================**/
const numeroALetras = (function() {
function Unidades(num) {
switch (num) {
case 1:
return 'UN';
case 2:
return 'DOS';
case 3:
return 'TRES';
case 4:
return 'CUATRO';
case 5:
return 'CINCO';
case 6:
return 'SEIS';
case 7:
return 'SIETE';
case 8:
return 'OCHO';
case 9:
return 'NUEVE';
}
return '';
} //Unidades()
function Decenas(num) {
let decena = Math.floor(num / 10);
let unidad = num - (decena * 10);
switch (decena) {
case 1:
switch (unidad) {
case 0:
return 'DIEZ';
case 1:
return 'ONCE';
case 2:
return 'DOCE';
case 3:
return 'TRECE';
case 4:
return 'CATORCE';
case 5:
return 'QUINCE';
default:
return 'DIECI' + Unidades(unidad);
}
case 2:
switch (unidad) {
case 0:
return 'VEINTE';
default:
return 'VEINTI' + Unidades(unidad);
}
case 3:
return DecenasY('TREINTA', unidad);
case 4:
return DecenasY('CUARENTA', unidad);
case 5:
return DecenasY('CINCUENTA', unidad);
case 6:
return DecenasY('SESENTA', unidad);
case 7:
return DecenasY('SETENTA', unidad);
case 8:
return DecenasY('OCHENTA', unidad);
case 9:
return DecenasY('NOVENTA', unidad);
case 0:
return Unidades(unidad);
}
} //Unidades()
function DecenasY(strSin, numUnidades) {
if (numUnidades > 0)
return strSin + ' Y ' + Unidades(numUnidades)
return strSin;
} //DecenasY()
function Centenas(num) {
let centenas = Math.floor(num / 100);
let decenas = num - (centenas * 100);
switch (centenas) {
case 1:
if (decenas > 0)
return 'CIENTO ' + Decenas(decenas);
return 'CIEN';
case 2:
return 'DOSCIENTOS ' + Decenas(decenas);
case 3:
return 'TRESCIENTOS ' + Decenas(decenas);
case 4:
return 'CUATROCIENTOS ' + Decenas(decenas);
case 5:
return 'QUINIENTOS ' + Decenas(decenas);
case 6:
return 'SEISCIENTOS ' + Decenas(decenas);
case 7:
return 'SETECIENTOS ' + Decenas(decenas);
case 8:
return 'OCHOCIENTOS ' + Decenas(decenas);
case 9:
return 'NOVECIENTOS ' + Decenas(decenas);
}
return Decenas(decenas);
} //Centenas()
function Seccion(num, divisor, strSingular, strPlural) {
let cientos = Math.floor(num / divisor)
let resto = num - (cientos * divisor)
let letras = '';
if (cientos > 0)
if (cientos > 1)
letras = Centenas(cientos) + ' ' + strPlural;
else
letras = strSingular;
if (resto > 0)
letras += '';
return letras;
} //Seccion()
function Miles(num) {
let divisor = 1000;
let cientos = Math.floor(num / divisor)
let resto = num - (cientos * divisor)
let strMiles = Seccion(num, divisor, 'UN MIL', 'MIL');
let strCentenas = Centenas(resto);
if (strMiles == '')
return strCentenas;
return strMiles + ' ' + strCentenas;
} //Miles()
function Millones(num) {
let divisor = 1000000;
let cientos = Math.floor(num / divisor)
let resto = num - (cientos * divisor)
let strMillones = Seccion(num, divisor, 'UN MILLON DE', 'MILLONES DE');
let strMiles = Miles(resto);
if (strMillones == '')
return strMiles;
return strMillones + ' ' + strMiles;
} //Millones()
return function NumeroALetras(num, currency) {
currency = currency || {};
let data = {
numero: num,
enteros: Math.floor(num),
centavos: (((Math.round(num * 100)) - (Math.floor(num) * 100))),
letrasCentavos: '',
letrasMonedaPlural: currency.plural || 'PESOS CHILENOS', //'PESOS', 'Dólares', 'Bolívares', 'etcs'
letrasMonedaSingular: currency.singular || 'PESO CHILENO', //'PESO', 'Dólar', 'Bolivar', 'etc'
letrasMonedaCentavoPlural: currency.centPlural || 'CHIQUI PESOS CHILENOS',
letrasMonedaCentavoSingular: currency.centSingular || 'CHIQUI PESO CHILENO'
};
if (data.centavos > 0) {
data.letrasCentavos = 'CON ' + (function() {
if (data.centavos == 1)
return Millones(data.centavos) + ' ' + data.letrasMonedaCentavoSingular;
else
return Millones(data.centavos) + ' ' + data.letrasMonedaCentavoPlural;
})();
};
if (data.enteros == 0)
return 'CERO ' + data.letrasMonedaPlural + ' ' + data.letrasCentavos;
if (data.enteros == 1)
return Millones(data.enteros) + ' ' + data.letrasMonedaSingular + ' ' + data.letrasCentavos;
else
return Millones(data.enteros) + ' ' + data.letrasMonedaPlural + ' ' + data.letrasCentavos;
};
})();
/*============================ END OF FUNCTION ============================ numeroALetras */