   Using glutBitmapCharacter
  Hi everyone,I have a 'timer' in my program which I display it on the graphics using glutBitmapCharacter.void render_text(float x, float y, char* s){glRasterPos2f(x,y);for ( unsigned int i=0; i < strlen( s ); i++ )glutBitmapCharacter(GLUT_BITMAP_9_BY_15,s);}Above is the function I use, and I call it like below:snprintf(text_buffer, 40, "Fill Time: %d Sec", filltime );glColor3f(1.0f, 1.0f, 1.0f);render_text( 10-Gc, 5+Gc, text_buffer );However, this works fine with integers, but when I try to use double or float (sometimes my filltime gets down to decimal numbers), this craps out.I need it to display down to 2nd decimals. (i.e. 0.02 sec, 0.03 sec etc)Not sure what to do at this point, I'm a fairly newbew to this...Please help!   
  IIRC, the format code %d is a placeholder for an integer value, not a floating-point value. You might try %f instead (you should be able to specify the precision as well, but I don't remember the syntax for this off the top of my head).Also, are you programming in C, or C++? C++ offers some additional tools for performing lexical conversions that are a little safer (and can be easier to use) than printf() and friends.   ;  Thank you.I was able to display decimals by simply changing %d to %f.But now it is displaying down to 0.00000n, which is too many.I know how to set the precision when doing couts but not sure what to do for this case.It would be great if you could give me a guide.Thanks.   ;Quote:Original post by pkiskoolThank you.I was able to display decimals by simply changing %d to %f.But now it is displaying down to 0.00000n, which is too many.I know how to set the precision when doing couts but not sure what to do for this case.It would be great if you could give me a guide.Thanks.Since you mention cout, I'm assuming you're programming in C++? If so, why not just use std::stringstream for this? Since you already know how to set the precision using C++ stream classes, it seems like this would be a more straightforward solution.   ;  Yes - I am using c++.and sorry, I have no clue what std::stringstream is about and how to use it...All I know is:double f = 3.1452;cout << setprecision (2) << f;I suppose this is irrelevant to std::stringstream...Please help.   ;Quote:Original post by pkiskoolYes - I am using c++.and sorry, I have no clue what std::stringstream is about and how to use it...All I know is:double f = 3.1452;cout << setprecision (2) << f;I suppose this is irrelevant to std::stringstream...Please help.No, it's relevant :) You would actually use an object of type stringstream in exactly the same way.I'd recommend searching the forum archives for (e.g.) 'stringstream', 'boost lexical_cast', and 'int to string'; you should find at least a few threads showing exactly how to do what you're asking about.   ;  Thanks.I'll look into that.   