心计%的完成了进度对话框 [英] Calculating percent done for progress dialog
问题描述
我试图用一个进度对话框,显示了多久,直到2时密集的功能就完成了。
在我的第一个功能,我有总数达到DB条目和我已经多少次通过一个做了/ while循环的计数器。当无法完成进度对话框应在50%</ P>
让我做的:
双总=(计数器/ dbEntries)* 100; //计数器和dbEntries都是廉政局
然后我把总由 2
,因为我想完成一半的数量,因为有2个功能
双realPercentDone =总/ 2.0;
这么说计数器3
和 dbEntries是36
将等于 0.08或8 %时,乘以100
,但总的始终是0。我究竟做错了什么?
如果柜台
和 dbEntries
都是整数那么它很可能在你的第一八佰伴pression括号执行整数除法。 3 DIV 36 = 0
。
试着将其更改为是这样的:
双总= 100.0 *计数器/ dbEntries;
或
双总=(1.0 *计数器/ dbEntries)* 100.0;
请注意:使用 100.0
,而不是 100
这样的浮点计算都做了
I am trying to use a progress dialog to show how long until 2 time intensive functions are done.
in my first function I have the total number to db entries and a counter for how many times i have gone through a do/while loop. when that gets done the progress dialog should be at 50%
so I do:
double total = (counter/dbEntries)*100; //counter and dbEntries are both int's
then I divide total by 2
because I want half the amount done because there are 2 functions
double realPercentDone = total/2.0;
so say counter is 3
and dbEntries is 36
that would equal 0.08 or 8% when multiplied by 100
but total is always 0. What am I doing wrong?
If counter
and dbEntries
are both integers then it is likely performing integer division in the parenthesis of your first expression. 3 div 36 = 0
.
Try changing it to something like this:
double total = 100.0 * counter / dbEntries;
or
double total = (1.0 * counter / dbEntries) * 100.0;
Note: use 100.0
and not 100
so as floating point calculations are done.
这篇关于心计%的完成了进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!