Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If I use :
CString tempo =_T("0.0057");
double d_tempo = _ttof(tempo);


d_tempo = 0.0000 so _ttof is wrong

What I have tried:

I tried with atof but it's the same thing
Posted
Updated 2-Aug-22 8:22am
Comments
Richard MacCutchan 2-Aug-22 11:49am    
I just tried that and it works perfectly, as it probably does in thousands of applications around the world. There is some information that you are not showing us.
0x01AA 2-Aug-22 14:52pm    
Are you working in debugger and you don't use d_tempo after that conversion? E.g. my compiler would optimize that in a way I can't trust then the result in the debugger. To avoid that I simply add code like this: if (d_tempo > 0.0);
Member 14594285 3-Aug-22 3:28am    
My result is d_tempo = 0.0000 and not 0.0057
0x01AA 3-Aug-22 4:34am    
Yes, I understand that. But how you inspect d_temp? With debugger? And if yes, there is a chance that the compiler does 'optimize away' the assignement to d_temp when you don't use d_temp after assignement.
Again: To be sure that it is not 'compiler optimation side effect' do something like

CString tempo =_T("0.0057");
double d_tempo = _ttof(tempo);
if (d_tempo > 0.0);


Of course if you use d_tempo anyhere else the above is not necessary...

Just like Richard, it works without changing anything. Since the function expects pointers, the alternatives would be:
C++
CString tempo = _T("0.0057");
double d_tempo = _ttof(tempo.GetBuffer());

wchar_t const* tempo2 = _T("0.0057");
double d_tempo2 = _ttof(tempo2);
 
Share this answer
 
You have some string issue with unicode. Read the Microsoft documentation.

You may use the define
_UNICODE
or use
C++
wcstod()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900