-2

I have some code that divides the number of elements in a collection by one hundred. But in the end it shows the wrong value.

private void FillPages()
        {
            double numofpages = listcoinslist.Count / 100;
            MessageBox.Show(listcoinslist.Count + " " + numofpages);
        }

The picture of the calculation result

I should get 65.6, instead I get 65. The same number is displayed on the label. This is not a display error, but a strange calculus error.

2 Answers2

1

This is due to rounding to int values because both values seem to be ints. Make sure you have at least one decimal number.

Make sure you devide with a float or double by adding .0, for example:

double numofpages = listcoinslist.Count / 100.0;

Waescher
  • 4,884
  • 3
  • 32
  • 46
0
double numofpages = (double)listcoinslist.Count / 100;

The problem was that you need to specify the number of elements in the collection as double.