-4

How to add zero as prefix if value less than equals to 9, i am using below way of achieving this:

            int countZero = 0;

            if(countVat <= 9)
            {
                countVat = countZero + countVat;
                Log.d("countVat:", String.valueOf(countVat));
            }

but this not works for me, still getting single digit if countVat value less than equals to 9.

Sonali
  • 773
  • 3
  • 11
  • 26

1 Answers1

3

Use String.format

String.format("%02d", num);
Leonardo Cardoso
  • 1,174
  • 2
  • 12
  • 22