这是我的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