Conversion from float to double
Hi, i have a problem with converting a float to a double.
I want the double value to be the exact same value as the float value
Code:
float fValue(250.840);
double dValue(0.0);
dValue = static_cast<double>(fValue);
The value in dValue is 250.83999633789 instead of 250.8400000000
Can someone help me out?
output values against watch values
This is the used code:
float fValue(250.84f);
double dValue(0.0);
dValue = static_cast<double>(fValue);
cout<<fValue<<endl;
cout<<dValue<<endl;
When I put a breakpoint on the first cout statement, the value of fValue is in the debugger 250.840. The value of the dValue is 250.83999633789.
When continue the program, the output on screen is 250.84 for each value.
But this is not correct because to my opponion the cout-statement interprets the dValue as a float and rounds the value automatically. In real world I'm not using the values to output them on screen. I work with the binary data (the 4 bytes of the float and the 8 bytes of the double value) and I perform calculations on these double-values. Therefor I must have the exact same values for the double type as for the float type.
Any solutions?