Java Code Examples for java.text.DecimalFormat.setGroupingSize()

The following are Jave code examples for showing how to use setGroupingSize() of the java.text.DecimalFormat class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: util4j   File: TestDecimalFormat.java   Source Code and License Vote up 6 votes
public static void test2(DecimalFormat df) {
	int number = 155566;
	//默认整数部分三个一组,
	System.out.println(number);//输出格式155,566
	//设置每四个一组
	df.setGroupingSize(4);
	System.out.println(df.format(number));//输出格式为15,5566
	DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance();
	//设置小数点分隔符
	dfs.setDecimalSeparator(';');
	//设置分组分隔符
	dfs.setGroupingSeparator('a');
	df.setDecimalFormatSymbols(dfs);
	System.out.println(df.format(number));//15a5566
	System.out.println(df.format(11.22));//11;22
	//取消分组
	df.setGroupingUsed(false);
	System.out.println(df.format(number));
}