percent calculation not working?

.net-4.0, c#, percentage

Solution

Don't multiply by 100, the Percent Format Specifier will do that for you. Just cast to `double` when you perform the division:

double perc = (double)item.Count / (double)query.Count;
MessageBox.Show(perc.ToString("P5"));

Problem

Its a very interesting thing not sure why it happens but when I do: ``` (item.Count / query.Count) * 100 ``` It will not give me any errors just reply with 0 and when I do: ``` (item.Count * 100) / query.Count ``` It works just fine, what am I missing here ? Another problem I am having is formatting the output of it to string: ``` double perc = (item.Count * 100) / query.Count; MessageBox.Show(perc.ToString("P5")); ``` Does not work gives me a huge sum like `33,333.33` or `33,000.00`, I wanted it to look like this `33.33%`, I tried several variations but for some reason it will not let me get the `.33` if I set the parenthesis to double it gets me `.00` and if I do not it doesn't give me `.33`

Original source