I need to calculate the percent but when I put a float value in the textbox the variable convert the value to an int value.
float intereses = 0, monto = 0, total = 0;
intereses = float.Parse(textBox1.Text);
monto = float.Parse(txtMonto.Text);
total = ((monto * intereses)/100);
MessageBox.Show("El "+textBox1.Text+" % de "+monto+" es "+ total);
First, that's not necessary initialize variables in the first line.
If i'm not wrong, For the problem, maybe your UI framework(DevExpress) or windows form component cannot recognize "."
character in the textbox
when you're trying to convert(.Parse)
or validate it to float type
.
total = ((5000* 05)/100); Debug: 250
And why you didn't try to put intereses
in MessageBox.Show("El "+textBox1.Text+" % de "+monto+" es "+ total);
instead of textBox1.Text
to see what's the exact problem?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.