Duda como pasar valor numerico a letras

Aquí puedes preguntar o compartir tus dudas y conocimientos acerca del programa
abood1987 escribió:
16 Ago 2019 16:31
welcome again Agotaras123
Sorry for the delay due to a little busy :friends:
In this example you can only up to 100
If you want to increase, read the text file called Numbers in the Docs folder and put more in the same way
The method you have adopted is the easiest way possible
this is my easy code :
HIDE: ON
Hidebb Message Hidden Description


HIDE: ON
Hidebb Message Hidden Description



:yes: :yes: :yes:
Super genial muchas gracias colega este si funciona perfectamente con todos los requerimientos, te lo agradezco mucho.
tnks abood .....
great work :lol: :lol:
ni voy a citar el primer mensaje de este hilo porque me da una embolia :motherofgod-1417755937:
Pabloko escribió:
16 Ago 2019 19:09
ni voy a citar el primer mensaje de este hilo porque me da una embolia :motherofgod-1417755937:
me lo imagino, tenes alguna mejor manera de hacer esto?

encontré esta pagina que hace lo mismo pero el proceso de resultado es mucho pero mucho mas rápido, porque el el ultimo ejemplo dado por el colega abood1987 entre mayor sea la cantidad de números en el txt mas lento es el resultado

Código: Seleccionar todo

https://buscapalabras.com.ar/escribe-numero.php

Encontré este código en JAVAScrip para que lo vena a ver si es posible pasarlo a lua

var numeroALetras = (function() {

// Código basado en https://gist.github.com/alfchee/e563340276f89b22042a
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;
};

})();

// Modo de uso: 500,34 USD
numeroALetras(500.34, {
plural: 'dólares estadounidenses',
singular: 'dólar estadounidense',
centPlural: 'centavos',
centSingular: 'centavo'
});
I've deleted repetition was not required and has no effective feasibility
Without using any repeating function :

HIDE: ON
Hidebb Message Hidden Description

So it's much faster :dancing: :dancing: :dancing:

Tell me what you think and comment after the experiment :friends: :friends: :friends:
Of course you can add more inside the text file just as it does
:yeah-1417757020:
read the text file called Numbers in the Docs folder and put more in the same way
HIDE: ON
Hidebb Message Hidden Description
and this is an example from 1 ...... 1000

Imagen

HIDE: ON
Hidebb Message Hidden Description


There is only one mistake I leave you to discover for yourself and tell me about him .
te dejo aquí el ejemplo que me pasaste vos con unos cambios y con los números hasta 111,999.00

usalo y veras lo que digo sobre el tiempo que tarda en dar un resultado.

HIDE: ON
Hidebb Message Hidden Description

HIDE: ON
Hidebb Message Hidden Description

HIDE: ON
Hidebb Message Hidden Description


te dejo solo el archivo de texto con los numeros para que hagas las pruebas con ese y veas lo lento que funciona.

HIDE: ON
Hidebb Message Hidden Description

HIDE: ON
Hidebb Message Hidden Description

HIDE: ON
Hidebb Message Hidden Description
another server please i can't download from him "Dropbox is not agood Server now"

Imagen
Really great, congratulations abood1987
I see it still helps many in this forum different from some that only criticizes.
dripro escribió:
17 Ago 2019 20:16
Really great, congratulations abood1987
I see it still helps many in this forum different from some that only criticizes.
Qué maravilloso interactuar con todos
Gracias también por sus maravillosas contribuciones al foro.
abood1987 escribió:
17 Ago 2019 20:01
another server please i can't download from him "Dropbox is not agood Server now"

Imagen
solo da clic en download igual lo voy a subir a otro servidor para que lo puedas descargar.
apz
HIDE: ON
Hidebb Message Hidden Description


txt
HIDE: ON
Hidebb Message Hidden Description
no tiene ningún sentido hacer listados pesados de números o interminables cadenas de ifelse... hacer lo que quieres es sencillo con las normas gramaticales del castellano, obviamente en cada idioma varía, asi que hay que segir la norma de la RAE en el caso del castellano: http://lema.rae.es/dpd/srv/search?id=QHaq7I8KrD6FQAyXTS

Imagen

Lo logico en este caso es descomponer el numero en las fracciones numerales desde mayor a menor e ir eliminando numeros hasta acabar. He hecho un ejemplo rapido en 5 minutos como demo:

HIDE: ON
Hidebb Message Hidden Description


apenas unas lineas con las que puedes llegar a 12 caracteres por numero, añadir decimales debería ser super sencillo con este código.

es raro probar cualquier otro método que no sea este para hacer esta tarea... :mindblown-1414029295:
Pabloko escribió:
19 Ago 2019 08:39
no tiene ningún sentido hacer listados pesados de números o interminables cadenas de ifelse... hacer lo que quieres es sencillo con las normas gramaticales del castellano, obviamente en cada idioma varía, asi que hay que segir la norma de la RAE en el caso del castellano: http://lema.rae.es/dpd/srv/search?id=QHaq7I8KrD6FQAyXTS

Imagen

Genial Pablo sin duda eres un genio en esto, yo no tenia idea real mente de como hacer esto y sin duda alguna lo que has hecho es lo que se ocupaba
, muchas gracias voy a leer bien esa documentacion que dejaste.
oh Pablo very good way :dancing:
You are a great programmer and wonderful thinker :yes:
Big thanks to you :yeah-1417757020:
he hecho algunos arreglos al codigo para manejar los espacios vacíos y un bug en los miles
--ES_es number to numeral string
function roll(num)
	local out = ""
	local numz = {
		["0"] = "cero",
		["1"] = "uno",
		["2"] = "dos",
		["3"] = "tres",
		["4"] = "cuatro",
		["5"] = "cinco",
		["6"] = "seis",
		["7"] = "siete",
		["8"] = "ocho",
		["9"] = "nueve",
		["10"] = "diez",
		["11"] = "once",
		["12"] = "doce",
		["13"] = "trece",
		["14"] = "catorce",
		["15"] = "quince",
		["16"] = "dieciseis",
		["17"] = "diecisiete",
		["18"] = "dieciocho",
		["19"] = "diecinueve",
		["20"] = "veinte",
		["30"] = "treinta",
		["40"] = "cuarenta",
		["50"] = "cincuenta",
		["60"] = "sesenta",
		["70"] = "setenta",
		["80"] = "ochenta",
		["90"] = "noventa"
	}
	if (#num>6 and #num<13) then
		nc = #num - 6
		n = String.Mid(num, 1, nc)
		num = String.Mid(num, nc+1, 6)
		if (n=="1") then
			out=out.."un millon "
		else
			result = String.Replace(roll(n), "y uno", "y un", false);
			out=out..result.." millones "
		end
		--out = String.Replace(out, "e y ", "i", false);
	end
	if (#num==6) then
		n = String.Mid(num, 1, 3)
		m = String.Mid(num, 1, 1)
		ret = roll(n)
		if (m~="0") then
			out = out..ret.." mil "
			num = String.Mid(num, 4, 3)
		else
			--out = out..ret
			num = String.Mid(num, 3, 4)
		end
		
	end
	if (#num==5) then
		n = String.Mid(num, 1, 2)
		m = String.Mid(num, 1, 1)
		ret = roll(n)
		if (m~="0") then
			out = out..ret.." mil "
			num = String.Mid(num, 3, 3)
		else
			--out = out..ret
			num = String.Mid(num, 2, 4)
		end
		
	end
	if (#num==4) then
		n = String.Mid(num, 1, 1)
		if (n~="0") then
			if (n~="1") then
				out=out..numz[n]
			end
			out=out.." mil "
		end
		num = String.Mid(num, 2, 3)
	end
	if (#num==3) then
		if (num=="100") then
			out=out.."cien "
		else
			n = String.Mid(num, 1, 1)
			if (n=="1") then
				out = out.."ciento "
			elseif (n=="5") then
				out = out.."quinientos "
			elseif (n=="7") then
				out = out.."setecientos "
			elseif (n=="9") then
				out = out.."novecientos "
			else
				if (n~="0") then
					out=out..numz[n].."cientos "
				end
			end
		end
		num = String.Mid(num, 2, 2)
	end
	if (#num==2) then
		if (numz[num]~=nil) then
			out = out..numz[num]
		else
			n = String.Mid(num, 1, 1)
			if (n=="0") then
				n = String.Mid(num, 2, 1)
				if (n~="0") then
					out = out..numz[n]
				end
			else
				m = String.Mid(num, 2, 1)
				out = out..numz[n.."0"].." y "..numz[m]
			end
		end
		num=""
	end
	if (#num==1) then
		out = out..numz[num]
	end
	return out
end
num = Input.GetText("Input1")
out = roll(num)
out = String.Replace(out, "e y ", "i", false);
out = String.Replace(out, " uno mil ", " un mil ", false);
out = String.Replace(out, " mil ", "mil ", false);
Dialog.Message("",out)
probablemente necesite mas ajustes pero es facil de seguir, simplemente ir descomponiendo recursivamente el numero
Genial creo que ya le entendí algo al código, muchas gracias Pabloko
gracias
Veamos que hay de nuevo en esto :pc:
Que buen trabajo. Gracias.
A PROBAR