Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have this number:
46.71438243077313

and I want to convert in cstring
I tried:
rend.Format(_T("%.2f", 46.71438243077313));


but it doesn't work

What I have tried:

I searched in internet and I have tried everything..but it doesn't work..I don't know..the result is always 0.000000
Posted
Updated 21-Oct-19 3:47am
v2

1 solution

Try:
C++
CString str;
str.Format(_T("%.2f"), 46.71438243077313);


Quote:
it doesn't work
Quote:
the result is 0.00

And how - exactly - did you check that? What code did you use? Because when I try it:
C++
#include <iostream>
#include <atlstr.h>

int main()
{
    std::cout << "Hello, world!\n";
    CString str;
    str.Format(_T("%.2f"), 46.71438243077313);
    std::cout<< str;
}
I get this:
Quote:
/LIBPATH:C:\boost_1_60_0\stage\lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
Hello, world!
46.71
Which is what I expect...
 
Share this answer
 
v3
Comments
Member 14594285 21-Oct-19 9:58am    
it doesn't work
OriginalGriff 21-Oct-19 10:00am    
"it doesn't work" is one of the most common problem reports we get here.
It's also the most useless, because it tells us nothing at all about what your problem actually is.

And we don't know, because we can't see your screen, we can't access your HDD, and we can't read your mind.
So explain it to us: tell us what you did to cause the problem. Tell us what happened when you did that. Show us any error messages, show us which line it occurred on if you can.

But "it doesn't work" tells us absolutely nothing.
Member 14594285 21-Oct-19 10:07am    
the result is 0.00
OriginalGriff 21-Oct-19 10:26am    
ANswer updated.
Member 14594285 21-Oct-19 10:56am    
my result is always 0.00

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