![](/img/trans.png)
[英]why does my float variable statement keeps on giving me an 'Cannot implicitly convert type double to float' error?
[英]Why does my float variable is not taking the correct value from the textbox?
我需要計算百分比,但是當我在文本框中放置一個浮點值時,變量將該值轉換為一個 int 值。
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);
首先,沒有必要在第一行初始化變量。
如果我沒記錯的話,對於這個問題,也許你的 UI 框架(DevExpress)或 windows 表單組件無法識別"."
當您嘗試convert(.Parse)
或將其驗證為float type
時textbox
的字符。
總計 = ((5000* 05)/100); 調試:250
以及為什么您不嘗試將intereses
放在MessageBox.Show("El "+textBox1.Text+" % de "+monto+" es "+ total);
而不是textBox1.Text
來查看確切的問題是什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.