I need simple math operations with some floats like "3.3 - 2.6". The result is 0.700001. I have no idea why there are numbers like 0.700001.
Can you help me please?
I need simple math operations with some floats like "3.3 - 2.6". The result is 0.700001. I have no idea why there are numbers like 0.700001.
Can you help me please?
The computer handles numbers in binary format with finite precision. Various simple decimal numbers cannot be precisely represented, so it gives the closest answer possible.
The usual way of dealing with the problem is simply to limit the precision you actually display. If you're using C++ streams for output then the std::fixed
and std::setprecision
manipulators should help.
Maybe that happens because of float precision. Try using double.