I can not divide two numbers correctly

后端 未结 6 647
情深已故
情深已故 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:21

    Check your integer math. Your code won't work without casting for small values, so just move the operations around:

    int percent = 100*score/numberOfQuestions;
    

提交回复
热议问题