When representing double
number its precision corrupts in some degree. For example number 37.3 can be represented as 37.29999999999991.
I need reestablishing of corrupted double
number (My project requires that). One approach is converting double
into CString
.
double d = 37.3;
CString str;
str.Format("%.10f", d);
Output: str = 37.3;
By this way I could reestablish corrupted d
. However, I found a counterexample. If I set
d = 37.3500;
then its double
representation sometimes be equal to 37.349998474121094. When converting d
to CString
output is still 37.3499984741, which is not equal to 37.3500 actually.
Why converting 37.3500 didn't give desired answer, while 37.3 gave? Is there any ways to reestablish double?
Thanks.