Calculating the length of a number for a dot matrix display

I'm using a 32x8 dot matrix display. It will display a number between 0 and 1999999 without leading zeros. The plan is to centralise it on the display. To do this I need to know how wide it is on the display. Each '1' is two pixels, every other digit is 4 pixels. I suppose I need to know how many 1s there are and how many digits in total. How would I go about finding this information? I'm currently just using the number of digits, which I'm calculating by seeing if it is bigger than 9, 99, 999 etc, but it doesn't look good if there are lots of 1s.

Does this come close

int pixelWidth(unsigned long value)
{
int pixCount=0;
if(value==0)
  return 4;
while(value > 0)
  {if((value % 10) == 1)
      pixCount +=2;
   else
      pixCount +=4;
  value=value/10; //(drops LS digit)
  } 
return pixCount;
}

Perfect thanks.

Don't you have to convert the number to a string before you send it to the display in the first place? I would count the number of "1" characters and other characters in the string.

I've got library that does all the matrix interfacing so I just call a function in that and send the number out. None of the string handling happens in the code