小编use*_*825的帖子

华氏度和摄氏度之间的转换问题

我从一开始就有这个问题,这是华氏和摄氏之间的转换.

    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!?";
    }
Run Code Online (Sandbox Code Playgroud)

当我想从华氏温度得到摄氏温度时它会一直给我0,即使这个公式似乎对我来说也是如此.这有什么不对?
因为我认为问题出在这里:

        if (Celsius.Checked == true)
    {
        fahr = float.Parse(textBox1.Text); …
Run Code Online (Sandbox Code Playgroud)

c# temperature unit-conversion

2
推荐指数
2
解决办法
2685
查看次数

标签 统计

c# ×1

temperature ×1

unit-conversion ×1