// JP opened flex table

Click to See Complete Forum and Search --> : TextOut() and floats


Izzy101
July 9th, 2008, 07:24 PM
Ok so i wanted to test out some code and have a float variable shown on the window. So as far as i can tell there isnt any sort of output besides textout(). (I am fairly new to windows programming btw).

int test = 5;
wsprintf(buffer, L"V: %d", test);
.............
.............
TextOut(hDC, 50, 42, buffer,4);

Okay so this worked, the integer 5 was displayed. So thats great...
Now the entire point was to use a float/double.

float test = 5.1;
wsprintf(buffer, L"V: %f", test); //From what i have seen %f is the syntax
//if it is a float variable
.............
.............
TextOut(hDC, 50, 42, buffer,5);
And this did not work, the output comes out as 'V: %f'.
It does not seem to register the variable i am using.
Does anyone know why this isnt working? Or a better way of doing this?

VladimirF
July 9th, 2008, 09:25 PM
wsprintf(buffer, L"V: %f", test); //From what i have seen %f is the syntax
//if it is a float variableWhere did you see that? Not in the docs? wsprintf doesn't handle floating point parameters...
You might have confused it with swprintf().

Izzy101
July 9th, 2008, 09:34 PM
Wow yeah that did it, thanks a lot! I probably should have double checked it. So is this really the best way to display a float on screen?

Ayalaskin
July 11th, 2008, 12:19 AM
TextOut(hDC, 50, 42, buffer,4);

Dont forget to change the last parameter of TextOut,
with floats you will have more than 4 caracteres.

//JP added flex table