这应该相对简单。
我有什么:
int progress; // iteration we are on, starts at 0, always incr by 1
int percentage; // from 1 - 100, starts at 0
int percentage_trip; // derived from total_results / 100
int total_results; // lets say its 200 (note that it can be anything, like 939049)
我需要什么:
在上面的例子中,每次进度命中2,4,6,8等时,百分比整数应该加1(即百分比++;)
我的想法围绕着非常格式化的嵌套IF语句,我正在寻找正确的方法。
答案 0 :(得分:3)
int incrementAmount = total_results/100;
if (progress % incrementAmount) { percentage++; }