• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple math operation for a progress bar

 
Alonso Tapia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currenlty delevoping a progress bar for an application with a fixed number of iterations. I have an event listener that monitors the process so I know the current cicle of the process. My problem is when I try to calculate the percentage of the current cicle, relative to the total number of cicles. This is my code:



Fisrt, maybe mention that mon.getCurrentCicle() actually gets the cicles left rather than the current.

So, ciclos is a fixed number and epoca changes every cicle, but when I calculate the percenage with epoca_per it gets stuck at 0.
It's a very simple operation and I've confirmed that epoca actually changes, but I have no clue why epoca_per doesn't change.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try 100 * epoca / ciclos. The value of epoca must never rise above 21474836 if it is an int.

Why? You are doing integer division: 9999 / 10000 returns 0. If you want to get 99% from 9999 / 10000, you will have to try 100 * 9999 / 10000, which is evaluated as 999900 / 10000, which comes to 99.
 
Alonso Tapia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh so simple..
thanks!!
 
Benjamin Thvedt
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer division has been messing me up too...I didn't know you can multiply it by another int to get an anwser, I have just been using all doubles up until now!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic