谁能告诉我哪里出了问题。当我在计算器中输入低和高的方程式时,我得到低 = 118.129 高 = 113.629。
但由于某种原因,当我运行代码时,低和高都显示 119.0。
match_FRC = 82;//Double.parseDouble(FRC_match_textbox.getText().toString());
match_DTR = 1.455;//Double.parseDouble(DTR_match_textbox.getText().toString());
//math functions
low = Math.round((match_FRC * match_DTR)/((1/100)+1));
high = Math.round((match_FRC * match_DTR)/((5/100)+1));
最佳答案
您需要使用浮点常量而不是整数,例如:
low = Math.round((match_FRC * match_DTR)/((1.0 / 100)+1));
实际上,您的 ((1/100) + 1)
是一个整数表达式,其计算结果恰好为 1。
将 1
变为 1.0
(或将 100
变为 100.0
)将导致其他操作数的提升(以及整个表达式)转换为 float 。
关于java - 数学计算不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10865637/