I have a float with the value of e.g 57.400002. I use sprintf_s
to display the value on my GUI.
sprintf_s(xPosition, 19, "%f", xPositionValue);
How can I format the float so it displays as 57.40?
I have a float with the value of e.g 57.400002. I use sprintf_s
to display the value on my GUI.
sprintf_s(xPosition, 19, "%f", xPositionValue);
How can I format the float so it displays as 57.40?
sprintf_s(xPosition, 19, "%.2f", xPositionValue);
See http://www.cplusplus.com/reference/clibrary/cstdio/printf/ for more documentation on format codes.
sprintf_s(xPosition, 19, "%.2f", xPositionValue);
should do the trick doesn't it ?
Use the width and precision tags, just like printf
See http://www.cplusplus.com/reference/clibrary/cstdio/printf/
I think you would want the following:
sprintf_s(xPosition, 19, "%.2f", xPositionValue);