format number display in a IGUIStatic label

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
humorstar
Posts: 25
Joined: Sat Oct 04, 2008 3:50 am

format number display in a IGUIStatic label

Post by humorstar »

I am trying to display a float number in a static label.
If I use the following code, I got a long display of the float number. How can I format it, for example, like %.3f in the C/C++ format string, so that it shows only three digits after the point?

Code: Select all

        text_centripetal[0]->setText(core::stringw(centripetal[0]).c_str());
Thank you,
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Use the C format string :D

Code: Select all

c8 temp[20];
sprintf(temp, "%.3f", centripetal[0]);
text_centripetal[0]->setText(core::stringw(temp).c_str());
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
humorstar
Posts: 25
Joined: Sat Oct 04, 2008 3:50 am

Post by humorstar »

OK, that works. Thank you!
Post Reply