Possible Duplicate:
Add leading zeroes to number in Java?
I want to add prefix to my number. I have number which i want to convert it in 3 digits e.g if i pass 1 than it should return 001. Here is my code.
public int returnThreeDigitNo(int number)
{
int threeDigitNo = 0;
int length = String.valueOf(number).length();
if(length == 1)
{
threeDigitNo = 00+number;
}
if(length == 2)
{
threeDigitNo = 0+number;
}
if(length == 3)
{
threeDigitNo = number;
}
return threeDigitNo;
}
thanks in advance