我正在写一个做很多事情的程序,但其中一个是将Celcius转换为Fahrenheit.在我这样做之后,我决定允许反过来,这就是我所做的.当我将Celcius转换为Fahrenheit时,我得到了正确的答案,但由于某种原因,我在将华氏温度转换为Celcius时得到的答案略有不同.这是我的代码:
String celcius = jTextArea3.getText();
String fahren = jTextArea7.getText();
if (fahren.equals("")) {
double tempFahr;
double Input = Double.parseDouble(jTextArea3.getText());
tempFahr = Input * 9 / 5 + 32;
jTextArea7.setText(tempFahr + "");
}
else
{
double tempCelc;
double Input = Double.parseDouble(jTextArea7.getText());
tempCelc = (Input -32) * 5 / 9;
jTextArea3.setText(tempCelc + "");
}
Run Code Online (Sandbox Code Playgroud)
这是简单的代码,但我想知道它是否可能是我看不到的非常小的东西.我想这可能是我的公式,但我很确定它不是,我已经研究过了.有人可以帮忙吗?
我得到的答案的一个例子是:1 Celcius = 33.8 Fahrenheit 33.8 Fahrenheit = 0.9999999999999984 Celcius