Right adjust number on LCD

I want to right adjust a number within a certain block. The number can be between 1 and 3 digits long, and I would like the 1s, 10s, and hundreds place to stay in a consistent spot on the LCD screen. Right now the code I have is doing this:

        int offset = ceil(log(rms+1)/log(10));
        if( offset==0 ) offset = 1;
        lcd.clear();
        lcd.setCursor( 13-offset, 1 );
        lcd.print( rms );
        lcd.print( " mW" );

I'm just wondering if there's a more elegant way to figure out how many digits a number has without using logrithms.

void setup() 
{
  Serial.begin(115200);
  for (int aNumber = 0; aNumber < 110; aNumber++)
  {
    padNumber(aNumber);
    Serial.println(aNumber);
  }
}

void loop() 
{
}

void padNumber(int numberToPad)
{
  if (numberToPad < 10)
  {
    Serial.print("0");
  } 

  if (numberToPad < 100)
  {
    Serial.print("0");
  }
}

I'm just wondering if there's a more elegant way to figure out how many digits a number has without using logrithms.

Use sprintf() to format the data. One of the format specifier options allows you to control the number of characters output. You can tell sprintf() to always output three characters, automatically right justifying the value in the string. Then, just print the string.

char stg[4];
sprintg(stg, "%3d",  rms);
lcd.print(stg);

Like Paul points out sprintf() is elegant but when I use it in Bob's code it compiles to 3398 bytes space and 191 bytes ram. Bob's uses 2304 bytes space and 189 ram. So it appears to me that sprintf() has a fairly high overhead. If program space is tight that's something to think about.

However, will you get negative values? That means displaying a sign. Bob's approach breaks on negative values but is easily fixed and is still a good space saving approach. sprintf() has a width modifier that makes it elegant of course.

void setup()
{
  Serial.begin(115200);
  char stg[5];
  for (int aNumber = -110; aNumber < 110; aNumber++)
  {
    sprintf(stg, "%4.3d", aNumber);
    Serial.println(stg);
  }
}

void loop()
{
}

In my own projects I take Bob's approach.