int percent = (score/numberOfQuestions)*100;
progressText.setText(score+"/"+numberOfQuestions+" "+percent+"%");
无论我累什么,返回 0%。我尝试将其转换为 int、double、float
为什么对于 score=5 numberOfQuestions=8 这样的数字返回 0%?
最佳答案
问题是将两个整数相除得到结果的整数部分。因此,(score/numberOfQuestions)
将始终为 0。
你应该做的是
int percent = (score * 100 / numberOfQuestions);
然后 *100
会先被执行,然后除法会给你正确的结果。
关于java - 我不能正确划分两个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12825617/