這是我的Windows應用程序的一個佈局,將攝氏轉換爲華氏。問題是,當我嘗試輸入溫度時會顯示一些垃圾(例如:如果我輸入'3'則顯示'3.0000009'),有時它甚至會顯示堆棧溢出異常。輸出也沒有正確顯示:我如何讓應用程序正確輸入..?
cel.text
是攝氏的文本框。 fahre.text
是華氏文本框。
namespace PanoramaApp1
{
public partial class FahretoCel : PhoneApplicationPage
{
public FahretoCel()
{
InitializeComponent();
}
private void fahre_TextChanged(object sender, TextChangedEventArgs e)
{
if (fahre.Text != "")
{
try
{
double F = Convert.ToDouble(fahre.Text);
cel.Text = "" + ((5.0/9.0) * (F - 32)) ; //this is conversion expression
}
catch (FormatException)
{
fahre.Text = "";
cel.Text = "";
}
}
else
{
cel.Text = "";
}
}
private void cel_TextChanged(object sender, TextChangedEventArgs e)
{
if (cel.Text != "")
{
try
{
Double c = Convert.ToDouble(cel.Text);
fahre.Text = "" + ((c *(9.0/5.0)) + 32);
}
catch (FormatException)
{
fahre.Text = "";
cel.Text = "";
}
}
else
{
fahre.Text = "";
}
}
}
}
+0這似乎不是OP的問題 –
它甚至顯示堆棧溢出異常部分問題呢? – Zbigniew