[Solved] Why does a declared float calculate partially in integers?


When you use integer numbers in a division, the compiler understands that it has to perform an integer division.

std::cout << 4 / 3;

That means that 4 divided 3 equals 1, and the rest can be obtained by doing 4 % 3 (that’s the modulo operator)

If you want to get a floating point division, at least one of the operands has to be a floating point type. For example:

std::cout << 4.0 / 3;

Or:

std::cout << 4 / 3.0;

They can also be both floating points.

By doing this, you will be producing the expected output of 1.33333333333

solved Why does a declared float calculate partially in integers?