Jump to content

Somar textboxes com casas decimais


JohnnyMan22

Recommended Posts

Boa tarde a todos,

Estou com dificuldades para somar valores com casas decimais no asp.net usando o c#. Possuo 4 textboxes e pretendo que o programa some (instantaneamente) os valores que estarão a ser digitados no momento. O meu código soma apenas inteiros. Alguma sugestao?

 protected void TextBox1_TextChanged(object sender, System.EventArgs e)
    {     

        int first = 0;
        int second = 0;
        int third = 0;
        int forth = 0;

        if (Int32.TryParse(TextBox1.Text, out second) && Int32.TryParse(TextBox2.Text, out first)&& Int32.TryParse(TextBox3.Text, out forth)
            && Int32.TryParse(TextBox4.Text, out third))
            TextBox5.Text = (first + second + third + forth).ToString();
    }

Obrigado desde já.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.