我不知道为什么下面的数学运算给了我0.0
Mathematical_expression:
double percentageAmongAll = ((itemClickedID+1)/(parent.getCount()));
Logcat_Output:
06-14 13:46:53.176: I/MySavedLocation(19361): parent.getCount() = 3
06-14 13:46:53.176: I/MySavedLocation(19361): itemClickedID+1 = 2
06-14 13:46:53.176: I/MySavedLocation(19361): percentageAmongAll = 0.0
答案 0 :(得分:4)
itemClickedID+1
和parent.getCount()
是整数表达式。整数除法总是返回整数,因此2/3
返回0
,然后转换为0.0
。
double percentageAmongAll = ((double) itemClickedID+1)/(parent.getCount());
这会将itemClickedId
转换为double,因此将执行双重除法。