Thread: ...
View Single Post
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 04-16-2022 , 05:30   Re: Percentage
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
Yes, it's called division.



No, that is incorrect for two reasons. First, to get the percentage of the total progress, you simply divide the actual value by the total value (cProgress/Total)*100.

The other thing is that you're using integers so you are doing integer division which will means that cProgress / Total will always result in 0 provided that cProgress is less than Total.

To be able to do this, you need to convert to floating point values before doing the division. Alternatively, if you don't need the full precision, you can use integer division but you need to multiply cProgress by 100 first and then divide by Total: (cProgress * 100) / Total. This will effectively be the truncated value of the method using floating point values.
Corrected. I just went about settings float points all around.

Though the alternative point can do the job. I am not sure how precise the OP wants it.

Last edited by Moody92; 04-16-2022 at 05:34.
Moody92 is offline