让我们从一点数学开始。
目标体重 = 8.4 当前体重 = 9.1 当前体重 - 目标体重 = 0.7(你会这么认为)
if( obj != null && obj.targetWeight != null && obj.currentWeight != null) {
try {
double i = Double.parseDouble( obj.targetWeight );
double o = Double.parseDouble( obj.currentWeight);
//do something if target weight is a number
if(i>o){
outputEditText.setText ("Congratulations. you have passed your target weight");
}
else if (i<o){
outputEditText.setText(
"Your Target Weight is " + obj.targetWeight +obj.unit + "\n" +
"Your Current Weight is " + obj.currentWeight + "\n" +
"Difference is " + (o - i));
}
根据上述8.4-9.1 = 0.6999999999999993
目标权重和当前权重都是用户提供的输入,被解析为双精度。
有谁知道我做错了什么
非常感谢