how to draw a number in the thousands

I have a function to draw numbers 0 through 999, but now I'm working on a project that is going to require numbers in the thousands and possibly ten thousands. I was hoping I could just add a line to what I already have, but nothing I'm trying works. Any ideas?

1
2
3
4
5
  if (number > 99)
     glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, (char)(number/100 + '0'));
  if (number > 9)
     glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, (char)((number/10) % 10 + '0'));
  glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, (char)(number % 10 + '0'));
Why not format the number properly?
1
2
for (auto ch: std::to_string(number))
  glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ch);
How about:

1
2
3
4
void display_number(int num) {
    for (char digit: to_string(num))
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, digit);
}


EDIT: oops, should've refreshed before posting ....
Last edited on
Topic archived. No new replies allowed.