C ++ floating point issue Cout
3 answers
The correct way to create a permanent float separation is:
s = 10.f / 3.f; // one of the operands must be a float
Without a suffix, f
you perform division double
by providing a warning (from float
to double
).
You can also use one of the operands:
s = static_cast<float>(10) / 3; // use static_cast, not C-style casts
The result is correct division.
+4
source to share