There is no type casting. You are just calling conversion functions.
Read the documentation of the used function
QString::number(double)[
^].
The function has two more optional parameters which have default values when not passed. The relevant parameter is the third one which defines the precision (the number of significand digits to be printed to the string). This is shown by your debug output:
Both string values have only 6 significand digits and are therefore identical.
You might now ask why the printed double values also have only 6 significand digits. It is for the same reason:
The stream
<< operator
for double values uses also 6 significand digits when formatting the value. If you want more (or less) digits, you must specify the precision (with the C++ standard library it is
std::setprecision()
).
There are some general rules when printing floating point values to text files and reading them in later:
- The max. required precision must be known.
- Print values with the above precision plus one.
- Use the 'g' format when printing to ensure that the precision is not lost for very large and small numbers.
- Don't expect that the initial value that has been printed is binary identical to the one get back from string to double.