이것은 섭씨를 화씨로 변환하는 내 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