This chapter provides reference information about using floating point numbers with Web Services Client for C++.
The XML specification refers to the IEEE specification for floating point numbers. The specification lists that float and double have the following precision:
For float, with a mantissa able to represent any number in the range 1 > x > 1/223, this gives a minimum accuracy of 6 digits. Similarly, for double, with a mantissa able to represent any number in the range 1 > x > 1/252, this gives a minimum accuracy of 10 digits.
When displaying floating point numbers, you must ensure that any potential inaccuracies due to rounding errors, and so on are not visible. Therefore, to ensure the correct level of precision, for float types, instead of using:
printf( "%f", myFloat);
you must use the following formatting command:
printf( "%.6g", myFloat);
Similarly, to ensure the correct level of precision for double types, instead of using:
printf( "%f", myDouble);
you must use the following formatting command:
printf( "%.10g", myDouble);