#includeNote: on one C++ implementation, this prints 0.429993.main() { float a = 1000.43; float a = 1000.0; cout << a - b << '\n'; }
Disclaimer: Frustration with rounding/truncation/approximation isn't really a C++ issue. It's a computer science issue. However, people keep asking about it on comp.lang.c++, so here's a nominal answer.
Answer: Floating point is an approximation. The IEEE standard for 32 bit float supports 1 bit of sign, 8 bits of exponent, and 23 bits of mantissa. Since a normalized binary-point mantissa always has the form 1.xxxxx..., the leading 1 is dropped and you get effectively 24 bits of mantissa. The number 1000.43 (and many, many others) is not exactly representable in float or double format. 1000.43 is actually represented as the following bit pattern (the 's' shows the position of the sign bit, the 'e's show the positions of the exponent bits, and the 'm's show the positions of the mantissa bits):
seeeeeeeemmmmmmmmmmmmmmmmmmmmmmm 01000100011110100001101110000101The shifted mantissa is 1111101000.01101110000101 or 1000 + 7045/16384. The fractional part is 0.429992675781. With 24 bits of mantissa you only get about 1 part in 16M of precision for float. The double type provides more precision (53 bits of mantissa).