【发布时间】:2010-12-27 10:29:51
【问题描述】:
我从一开始就有这个问题 这是华氏和摄氏之间的转换。
private void button1_Click(object sender, EventArgs e)
{
float fahr, cel;
if (Celsius.Checked == true)
{
fahr = float.Parse(textBox1.Text);
cel = (5/9)*(fahr-32);
richTextBox1.Text = "The Degree in Celsius is:" + cel.ToString() + Environment.NewLine + "cool isn't it!?";
}
else if (Fahrenheit.Checked == true )
{
cel = float.Parse(textBox1.Text);
fahr = ((9 * cel)/5)+ 32;
richTextBox1.Text = "The degree in Fahrenheit is:" + fahr.ToString() + Environment.NewLine + "cool is it!?";
}
当我想从华氏温度获取摄氏温度时,即使公式对我来说似乎是正确的,它也会一直给我 0。
这里有什么问题?
因为我认为问题出在此处:
if (Celsius.Checked == true)
{
fahr = float.Parse(textBox1.Text);
cel = (5/9)*(fahr-32);
richTextBox1.Text = "The Degree in Celsius is:" + cel.ToString() + Environment.NewLine + "cool isn't it!?";
也许我的行动秩序有问题,但我认为这是真的? 谢谢你的帮助。
【问题讨论】:
标签: c# temperature unit-conversion