C# is rounding down divisions by itself

Solution 1:

i = 200 / 3 is performing integer division.

Try either:

i = (double)200 / 3

or

i = 200.0 / 3

or

i = 200d / 3

Declaring one of the constants as a double will cause the double division operator to be used.

Solution 2:

200/3 is integer division, resulting in an integer.

try 200.0/3.0

Solution 3:

200 / 3 this is an integer division. Change to: 200.0 / 3 to make it a floating point division.

Solution 4:

You can specify format string with the desired number of decimal ponits:

double i;
i = 200 / 3.0;
Messagebox.Show(i.ToString("F6"));

Solution 5:

Though the answer is actually 66.666, what is happening is that 200 / 3 is being calculated resulting in an integer. The integer is then being placed in the float. The math itself is happening as integer math. To make it a float, use 200.0 / 3. The .0 will cause it to treat 200 as a float, resulting in floating point math.