Java - How to format a number to a 2 char string?

后端 未结 3 1900
日久生厌
日久生厌 2021-02-18 12:56

How would I format an int between 0 and 99 to a string which is 2 chars. E.g

4  becomes \"04\"
36 becomes \"36\"

Than

3条回答
  •  不思量自难忘°
    2021-02-18 13:39

    You can do this using NumberFormat. E.g.,

    NumberFormat formatter = new DecimalFormat("00");
    String s = formatter.format(4); 
    

提交回复
热议问题