Fixed decimal numbers with JAVA

前端 未结 4 2012
感动是毒
感动是毒 2021-01-13 05:10

How do I represent numbers in the format

001 = 1
002 = 2
003 = 3
010 = 10
020 = 20

The number of digits is always 3.

4条回答
  •  北海茫月
    2021-01-13 05:50

    Am I missing something obvious here?

    String  num_str = "001"
    Integer val     = Integer.parseInt(num_str);
    String  answer  = val.toString();
    

提交回复
热议问题