-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.

4
  • Convert result inot String Commented Jul 7, 2014 at 8:07
  • countVat is int type of variable @Sharpedge Commented Jul 7, 2014 at 8:09
  • You are summing two int's. Convert them to String before summing. Commented Jul 7, 2014 at 8:13
  • int countZero = 0; if(countVat <= 9) { String str = "0" + countVat; Log.d("countVat :", str); } Commented Jul 7, 2014 at 8:47

1 Answer 1

3

Use String.format

String.format("%02d", num); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.