java 以0开头的数字计算,保留开头0

String ul="00009";
    int utellength=ul.length();
    String u="";
    for (int i = 0; i < utellength; i++) {
        u=u+"0";
        
    }
    System.out.println("u:"+u);
    BigInteger utel=new BigInteger(ul);//大数运算 取值范围比int  long  大
    BigInteger untel=new BigInteger(String.valueOf("200"));
    utel=utel.add(untel);
    System.out.println(utel);
    System.out.println("utel.toString():"+utel.toString());
     //NumberFormat去格式化
    NumberFormat nf = new DecimalFormat(u);//此处的参数u的位数就是你需要保留的数字位数
    String str = nf.format(utel);//这里的参数就是指需要转换的数字
    System.out.println("str:"+str);

原文地址:https://www.cnblogs.com/ttqi/p/13993183.html