using System.Text.RegularExpressions;
namespace QualitasApp.Util
private String[] UNIDADES = { "", "uno ", "dos ", "tres ", "cuatro ", "cinco ", "seis ", "siete ", "ocho ", "nueve " };
private String[] DECENAS = {"diez ", "once ", "doce ", "trece ", "catorce ", "quince ", "dieciseis ",
"diecisiete ", "dieciocho ", "diecinueve", "veinte ", "treinta ", "cuarenta ",
"cincuenta ", "sesenta ", "setenta ", "ochenta ", "noventa "};
private String[] CENTENAS = {"", "ciento ", "doscientos ", "trecientos ", "cuatrocientos ", "quinientos ", "seiscientos ",
"setecientos ", "ochocientos ", "novecientos "};
public String Convertir(String numero, bool mayusculas)
numero = numero.Replace(".", ",");
if (numero.IndexOf(",") == -1)
r = new Regex(@"\d{1,9},\d{1,2}");
MatchCollection mc = r.Matches(numero);
String[] Num = numero.Split(',');
if (int.Parse(Num[0]) == 0)
else if (int.Parse(Num[0]) > 999999)
literal = getMillones(Num[0]);
else if (int.Parse(Num[0]) > 999)
literal = getMiles(Num[0]);
else if (int.Parse(Num[0]) > 99)
literal = getCentenas(Num[0]);
else if (int.Parse(Num[0]) > 9)
literal = getDecenas(Num[0]);
literal = getUnidades(Num[0]);
return (literal + parte_decimal).ToUpper();
return (literal + parte_decimal);
private String getUnidades(String numero)
String num = numero.Substring(numero.Length - 1);
return UNIDADES[int.Parse(num)];
private String getDecenas(String num)
String u = getUnidades(num);
return DECENAS[int.Parse(num.Substring(0, 1)) + 8];
return DECENAS[int.Parse(num.Substring(0, 1)) + 8] + "y " + u;
private String getCentenas(String num)
if (int.Parse(num) == 100)
return CENTENAS[int.Parse(num.Substring(0, 1))] + getDecenas(num.Substring(1));
return getDecenas(int.Parse(num) + "");
private String getMiles(String numero)
String c = numero.Substring(numero.Length - 3);
String m = numero.Substring(0, numero.Length - 3);
return n + "mil " + getCentenas(c);
return "" + getCentenas(c);
private String getMillones(String numero)
String miles = numero.Substring(numero.Length - 6);
String millon = numero.Substring(0, numero.Length - 6);
n = getCentenas(millon) + "millones ";
n = getUnidades(millon) + "millon ";
return n + getMiles(miles);
static void Main(string[] args)
NumLetra nl = new NumLetra();
Console.WriteLine(nl.Convertir(numero,true));