add Zero for single digit number - Android java.lang

Android examples for java.lang:Integer

Description

add Zero for single digit number

Demo Code

public class Main {

  public static String addZerodata(int m) {
    if (m < 10) {
      return "0" + (String.valueOf(m));
    } else {//from   w  w  w.  ja  va  2s .  com
      return String.valueOf(m);
    }

  }

  public static String addZerodata(String str) {
    int m = Integer.parseInt(str);
    if (m < 10) {
      return "0" + (String.valueOf(m));
    } else {
      return str;
    }

  }

}

Related Tutorials