How to display heading with 3 digits.

Hello to all...
I´m dealing with a magnetometer data. I wish there should be a way to get Course/Heading (bearing data) in a 3 digits format (i.e.) 021 instead of 21, 003 instead of 3 etc.,
I´ve been searching about it but I can´t figure out the way to do it.
Is there any code to operate the 1,2 or 3 digits I have, to insert the "0´s" at the left?
Thanks in advance...

Sorry.. I meant 1 or 2 digits, with 3 digits is OK...

if (x < 100) 
{
  Serial.print ('0');
}
if (x < 10) 
{
  Serial.print ('0');
}
Serial.print (x);

or use sprintf.

Wow... amazing. :o :o

Thanks a million AWOL.