Calculating percent done for progress dialog

前端 未结 3 442
北恋
北恋 2021-01-22 12:39

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

3条回答
  •  一向
    一向 (楼主)
    2021-01-22 13:26

    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.

提交回复
热议问题