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

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
Updated 21-Oct-19 3:47am

1 solution

CString str;
str.Format(_T("%.2f"), 46.71438243077313);

it doesn't work
the result is 0.00

And how - exactly - did you check that? What code did you use? Because when I try it:
#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:
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
Hello, world!
Which is what I expect...
Share this answer
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