java string before the zero padding, a method trailing zeros

        String fileName = "130181";
        System.out.println("================  前补零方法一   =================");
        DecimalFormat g1=new DecimalFormat("0000000");
        String startZeroStr = g1.format(Integer.valueOf(fileName));
        System.out.println("前补零方法一:"+startZeroStr);

        System.out.println("================  前补零方法二   =================");
        startZeroStr = String.format("%07d",Integer.valueOf(fileName));
        System.out.println("前补零方法二:"+startZeroStr);

        System.out.println("================  后补零方法一   =================");
        DecimalFormat g2=new DecimalFormat("0.000000");
        String endZeroStr = g2.format(Integer.valueOf(fileName));
        System.out.println("后补零:"+endZeroStr);
        System.out.println("虽然后补零出现这种情况,带有小数点");
        System.out.println("比如你要长度要在7位以内,可以这么做");
        System.out.println("后补零转变后:"+endZeroStr.replace(".","").substring(0,7));

Export

================  前补零方法一   =================
前补零方法一:0130181
================  前补零方法二   =================
前补零方法二:0130181
================  后补零方法一   =================
后补零:130181.000000
虽然后补零出现这种情况,带有小数点
比如你要长度要在7位以内,可以这么做
后补零转变后:1301810

Of course, trailing zeros through the top, to know that behind more than make a few zeros, then the interception on the line, in fact, do not like the top so strenuous. Plus a bunch of content directly to zero, then the interception, the following method is 15 zeros up to a certain value, this is the most direct sense of the zeros. . .

(ynzlJjzz.getCode()+"0000000000000000").substring(0,15)

 

Published 92 original articles · won praise 3 · Views 5138

Guess you like

Origin blog.csdn.net/qq_22049773/article/details/103459141