Click here to Skip to main content
14,367,615 members
Rate this:
Please Sign up or sign in to vote.
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 4:47am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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...
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
OriginalGriff 21-Oct-19 10:59am
At the risk of repeating myself...

"And how - exactly - did you check that? What code did you use?"
Member 14594285 21-Oct-19 11:04am
rend.Format(_T("%.2f", 46.71438243077313));
OriginalGriff 21-Oct-19 11:10am
Is there any point at all in my typing, if you are just going to ignore what I say and do what you think will work?

Go back, read the code in my solution above, and compare that to teh code you just showed ...
Member 14594285 21-Oct-19 11:13am
my code it's the same of your and my result is 0.00, I don't see differences
Member 14594285 21-Oct-19 11:14am
now it works, thanks

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100