I can not divide two numbers correctly

后端 未结 6 505
情深已故
情深已故 2021-01-17 17:44
int percent = (score/numberOfQuestions)*100;
progressText.setText(score+\"/\"+numberOfQuestions+\"  \"+percent+\"%\");

returns 0% no matter what I

6条回答
  •  一整个雨季
    2021-01-17 18:17

    You're using an int (integer) to store that percentage. Try using float or double instead making score and number of questions float or double too (Thanks for teh comments, I totally skipped this...). If you have issues showing the value, I suggest you use DecimalFormat to format it.

    Rather than using pure int math to calculate and store the percentage, I suggest this other alternatives if you want to have decimals in your result.

提交回复
热议问题