simple calculation not working for some reason

后端 未结 4 811
耶瑟儿~
耶瑟儿~ 2020-11-28 17:15

Alright, I\'m trying to calculate the percentage of two values. This should be really simple but for some weird reason it\'s not working. I\'m too tired/dumb to figure it ou

4条回答
  •  离开以前
    2020-11-28 17:21

    Indeed, simple error, when doing diversions with int, the answer will be an int. Your answer would be between 0 and 1 so rounded down it is 0 (int).

    Use:

    int returnvalue = (int)((FilesCompleted / (double)TotalFilesCount) * 100);
    

    To make your calculation use a double for the fractional number and then multiply that by 100 and cast that to an int.

提交回复
热议问题