0
I have a small problem, I have a textbox that has a value in real "999.99" and writes a number in full, only that the textbox often receives an incomplete value like '23' etc., I want when the person type an incomplete value the program complete for me. Ex if I type '10' the complete program for '10,00'
Someone has a suggestion?
string n1 = "";
string Centavos_unidade = null, centavos_dezena = null;
string Unidade = "", Dezena = "";
string valor = "", virgula = "", Centena = "";
n1 = TxtNumeroExtenso.Text;
n1 = n1.PadLeft(7, '0');
string zero = "0000,00";
if (n1[5] == '1')
{
switch (n1.Substring(5))
{
case "10": centavos_dezena = "Dez"; break;
case "11": centavos_dezena = "Onze"; break;
case "12": centavos_dezena = "Doze"; break;
case "13": centavos_dezena = "Treze"; break;
case "14": centavos_dezena = "Quatorze"; break;
case "15": centavos_dezena = "Quinze"; break;
case "16": centavos_dezena = "Dezesseis"; break;
case "17": centavos_dezena = "Dezessete"; break;
case "18": centavos_dezena = "Dezoito"; break;
case "19": centavos_dezena = "Dezenove"; break;
}
}
else if (n1[5] != '0')
{
switch (n1[5])
{
case '2': centavos_dezena = "Vinte "; break;
case '3': centavos_dezena = "Trinta "; break;
case '4': centavos_dezena = "Quarenta "; break;
case '5': centavos_dezena = "Cinquenta "; break;
case '6': centavos_dezena = "Sessenta "; break;
case '7': centavos_dezena = "Setenta "; break;
case '8': centavos_dezena = "Oitenta "; break;
case '9': centavos_dezena = "Noventa "; break;
}
}
if (n1[6] != '0')
{
switch (n1[6])
{
case '1': Centavos_unidade = "Um"; break;
case '2': Centavos_unidade = "Dois"; break;
case '3': Centavos_unidade = "Três"; break;
case '4': Centavos_unidade = "Quatro"; break;
case '5': Centavos_unidade = "Cinco"; break;
case '6': Centavos_unidade = "Seis"; break;
case '7': Centavos_unidade = "Sete"; break;
case '8': Centavos_unidade = "Oito"; break;
case '9': Centavos_unidade = "Nove"; break;
}
}
present the code, a [MCVE]. And what platform are you talking about? Windows Forms, Web Forms, MVC, APP Console and etc
– Leandro Angelo
I posted a piece of code, eh a bit big so I summarized.
– Marcos Eduardo
A somewhat peculiar treatment and susceptible to many errors... but how do you want to identify when the user has not typed the pennies?
– Leandro Angelo
Very peculiar code, like @Leandro said. A simple form (and as peculiar as its code) would be to make an Index (',') of the input value, if -1 means that it does not exist, then you put '.00'.
– Kevin Kouketsu
Thanks for the tips I’ll try to use Indexof
– Marcos Eduardo