這應該是比較簡單的。顯示進度百分比
什麼我有:
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