# Easy 'StringCbPrintf' question (hopefully)

This topic is 4971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys, it's me again! First of all, here's my code to reference:
	int const arraysize = 30;
float TempTest;
TCHAR pszDest[arraysize];
size_t cbDest = arraysize * sizeof(TCHAR);

TempTest = 169474/495;

StringCbPrintf(pszDest, cbDest, "%d", TempTest);
What I'm trying to do is fill the variable 'pszDest' with a string representation of the floating point value in 'TempTest'. But all the above returns is zero! What am I doing wrong? BTW, for those of you that haven't played around with 'StringCbPrintf' it's exactly like using 'wsprintf' except without accidently aggravating those good old Windows security issues. I also get a ZERO in pszDest if I use 'wsprintf' in the place of 'StringCbPrintf'. Thanks in advance for the help! :)

##### Share on other sites
%d is the format code for a signed integer. You probably want to use %f, %g, %e or some other code meant for displaying floating point data.

I'm not sure exactly why it outputs 0, since it should be 'trash', but I believe the above will fix your problem.

##### Share on other sites
Thanks for the reply, Extrarius!

Yep, that %f did the trick... Pretty weird, because I tried that earlier today and it put the letter 'f' into pszDest. But now it works!

Thanks again! :)

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 10
• 12
• 20
• 12
• 13
• ### Forum Statistics

• Total Topics
632148
• Total Posts
3004450

×