Calculating Integer Percentage
Cast to double
first so it doesn't compute a division between integers
:
int totalProgress = (int)((double)FilesProcessed / TotalFilesToProcess * 100);
int FilesProcessed = 42;
int TotalFilesToProcess = 153;
int TotalProgress = FilesProcessed * 100 / TotalFilesToProcess;
Console.WriteLine(TotalProgress);
https://dotnetfiddle.net/3GNlVd
If you want to be more accuracy, you can use:
int TotalProgress = Convert.ToInt32(Math.Round(((decimal)FilesProcessed / TotalFilesToProcess) * 100, 0));
If the numbers are greater you will have a difference. For example
int FilesProcessed = 42;
int TotalFilesToProcess = 1530;
The result with decimals will be: 2.74%, if you use the previous methods, you would find 2%, with the formula I am proposing you will obtain 3%. The last option has more accuracy.