这应该是比较简单的。显示进度百分比
什么我有:
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语句,我是looki这样做的正确方法。
百分比不应该是'(progress/total_results)* 100'吗? – Danny
@Danny:整数算术需要'(progress * 100/total_results)'(希望没有溢出) - 你拥有的总是零,直到progress = total_results。 –
@AustinSalonen true。没有想到这一点。 – Danny