Java string string 0 or space

Here is the programming house jb51 CC collects and arranges code fragments through the network.

Programming house Xiaobian now shares it with you and gives you a reference.

package cn.com.songjy;

import java.text.NumberFormat;
//Java 中给数字左边补0
public class NumberFormatTest {

	public static void main(String[] args) {
		// 待测试数据
		int i = 1;
		// 得到一个NumberFormat的实例
		NumberFormat nf = NumberFormat.getInstance();
		// 设置是否使用分组
		nf.setGroupingUsed(false);
		// 设置最大整数位数
		nf.setMaximumIntegerDigits(4);
		// 设置最小整数位数
		nf.setMinimumIntegerDigits(4);
		// 输出测试语句
		System.out.println(nf.format(i));
	}
}
/**  
 * Java里数字转字符串前面自动补0的实现。  
 *    
 */  
public class TestStringFormat {   
  public static void main(String[] args) {   
    int youNumber = 1;   
    // 0 代表前面补充0   
    // 4 代表长度为4   
    // d 代表参数为正数型   
    String str = String.format("%04d",youNumber);   
    System.out.println(str); // 0001   
  }   
}  
//流水号加1后返回,流水号长度为4
	private static final String STR_FORMAT = "0000"; 

	public static String haoAddOne_2(String liuShuiHao){
	    Integer intHao = Integer.parseInt(liuShuiHao);
	    intHao++;
	    DecimalFormat df = new DecimalFormat(STR_FORMAT);
	    return df.format(intHao);
	}

The above is all the code content collected by the programming home (jb51. CC). I hope this article can help you solve the program development problems you encounter.

If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>