user10735: I have a simple code, part of which contains the calculation 800/1000, which seems to return a value of zero for some reason (even though I store it in a float variable). When I replace the calculation with the expected result (0.8) the code works as expected, I just wonder why the calculation doesn't produce the same result. 

user7856: Both 800.0/1000 or ((float)800)/1000 will work.
The former works only with hardcoded constants, while the latter works also with variables:
int a = 800;
int b = 1000;
float c = ((float)a) / b;


user10736: A whole numbers like 800 or 1000 are integers, while a number like 800.4 is considered fractional and is treated as a float. Two integers divided gives an whole integer result, in your case 0. If one number in the division is an integer, and one is a float, the result is a float.

10735: <p>I have a simple code, part of which contains the calculation 800/1000, which seems to return a value of zero for some reason (even though I store it in a float variable). When I replace the calculation with the expected result (0.8) the code works as expected, I just wonder why the calculation doesn't produce the same result. </p>
 7856: <p>Both 800.0/1000 or ((float)800)/1000 will work.</p>

<p>The former works only with hardcoded constants, while the latter works also with variables:</p>

<pre><code>int a = 800;
int b = 1000;
float c = ((float)a) / b;
</code></pre>
 10736: <p>A whole numbers like 800 or 1000 are integers, while a number like 800.4 is considered fractional and is treated as a float. Two integers divided gives an whole integer result, in your case 0. If one number in the division is an integer, and one is a float, the result is a float.</p>
