Original: http://www.open-open.com/code/view/1471488086408
PackageCn.com.songjy;ImportJava.text.NumberFormat;//0 in Java to the left of the number Public classNumberformattest { Public Static voidMain (string[] args) {//data to be tested inti = 1; //get an example of a NumberFormatNumberFormat NF =numberformat.getinstance (); //set whether to use groupingNf.setgroupingused (false); //To set the maximum number of integer digitsNf.setmaximumintegerdigits (4); //set the minimum number of integer digitsNf.setminimumintegerdigits (4); //Output Test StatementSystem.out.println (Nf.format (i)); }}/*** Java Digital to string in front of auto-complement 0 implementation. * */ Public classTeststringformat { Public Static voidMain (string[] args) {intYounumber = 1; //0 on behalf of the preceding supplement 0//4 for length 4//d for parameter is positive typeString str = String.Format ("%04d", Younumber); System.out.println (str); //0001 } } //serial number plus 1 returns, serial number length is 4 Private Static FinalString str_format = "0000"; Public Staticstring haoaddone_2 (String Liushuihao) {Integer Inthao=Integer.parseint (Liushuihao); Inthao++; DecimalFormat DF=NewDecimalFormat (Str_format); returnDf.format (Inthao); }
Java string string complement 0 or space