So I would like to calculate the percentage progress of my program as the nearest integer value
In my examples lets take
int FilesProcessed = 42;
int TotalFilesToProcess = 153;
So First I tried:
Int TotalProgress = ((FilesProcessed / TotalFilesToProcess) * 100)
This returned TotalProgress = 0
Then I tried
Int TotalProgress = (int)((FilesProcessed / TotalFilesToProcess) * 100)
This gives compiler error saying Cannot implicitly convert type decimal to int
Ive tried
Int TotalProgress = Math.Round((FilesProcessed / TotalFilesToProcess) * 100)
and get The call is ambiguous between decimal and double
and so now I've come here for help?
If we have to calculate percent of a number, divide the number by the whole and multiply by 100. Hence, the percentage means, a part per hundred. The word per cent means per 100. It is represented by the symbol “%”.
Percentage is calculated by taking the frequency in the category divided by the total number of participants and multiplying by 100%. To calculate the percentage of males in Table 3, take the frequency for males (80) divided by the total number in the sample (200). Then take this number times 100%, resulting in 40%.
Cast to double
first so it doesn't compute a division between integers
:
int totalProgress = (int)((double)FilesProcessed / TotalFilesToProcess * 100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With