CString to double conversion.
-
Hi all, I am trying to convert CString value to double value. see below
if(pos == 0) { assfile.ReadString(nextLine); pos = nextLine.Find(\_T(",")); temp = nextLine.Left(pos); dValue = \_wtof(temp); // dValue is double variable if (dValue < minval) minval = dValue; }
i am using _wtof() to convert string to double. The problem here is after conversion the double value has more decimal points every time. for example str = "234.555" after conversion the double value will be like this 234.55500005 i want the double value to be as it is in the string. how to resolve this? Thanks in advance. Regards, kumar
hi
-
Hi all, I am trying to convert CString value to double value. see below
if(pos == 0) { assfile.ReadString(nextLine); pos = nextLine.Find(\_T(",")); temp = nextLine.Left(pos); dValue = \_wtof(temp); // dValue is double variable if (dValue < minval) minval = dValue; }
i am using _wtof() to convert string to double. The problem here is after conversion the double value has more decimal points every time. for example str = "234.555" after conversion the double value will be like this 234.55500005 i want the double value to be as it is in the string. how to resolve this? Thanks in advance. Regards, kumar
hi
You can't control that. This is due to the precision of the double which is not perfect. I suggest you google about "floating point precision" to learn more about the subject (see this[^] for instance).
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Hi all, I am trying to convert CString value to double value. see below
if(pos == 0) { assfile.ReadString(nextLine); pos = nextLine.Find(\_T(",")); temp = nextLine.Left(pos); dValue = \_wtof(temp); // dValue is double variable if (dValue < minval) minval = dValue; }
i am using _wtof() to convert string to double. The problem here is after conversion the double value has more decimal points every time. for example str = "234.555" after conversion the double value will be like this 234.55500005 i want the double value to be as it is in the string. how to resolve this? Thanks in advance. Regards, kumar
hi
-
Hi all, I am trying to convert CString value to double value. see below
if(pos == 0) { assfile.ReadString(nextLine); pos = nextLine.Find(\_T(",")); temp = nextLine.Left(pos); dValue = \_wtof(temp); // dValue is double variable if (dValue < minval) minval = dValue; }
i am using _wtof() to convert string to double. The problem here is after conversion the double value has more decimal points every time. for example str = "234.555" after conversion the double value will be like this 234.55500005 i want the double value to be as it is in the string. how to resolve this? Thanks in advance. Regards, kumar
hi
As Cedric Moonen said, you cannot control this. But you can always choose what you want to be displayed by formatting the data. For example,
printf("%.3f", dValue);
will only show you 3 decimal digits. The same formatting can also be used withCStringT::Format
and other APIs likeStringCchPrintf
.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Did you try:
double dValue = 234.55500005;
long lValue = dValue * 1000;
dValue = lValue / 1000;I doubt!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You