import java.text.*;
public class Untitled1 {
public static void main(String[] args) {
//---------------------------------------------
//定义一个数字格式化对象,格式化模板为".##",即保留2位小数.
Decimalformat a = new Decimalformat(".##");
String s= a.format(333.335);
System.err.println;
//说明:如果小数点后面不够2位小数,不会补零.
//---------------------------------------------
//-----------------------------------------------
//可以在运行时刻用函数applyPattern(String)修改格式模板
//保留2位小数,如果小数点后面不够2位小数会补零
a.applyPattern(".00");
s = a.format(333.3);
System.err.println;
//------------------------------------------------
//------------------------------------------------
//添加千分号
a.applyPattern(".##\u2030");
s = a.format(0.78934);
System.err.println;
//------------------------------------------------
//------------------------------------------------
//添加百分号
a.applyPattern("#.##%");
s = a.format(0.78645);
System.err.println;
//------------------------------------------------
//------------------------------------------------
//添加前、后修饰字符串,记得要用单引号括起来
a.applyPattern("'这是我的钱$',###.###'美圆'");
s = a.format(33333443.3333);
System.err.println;
//------------------------------------------------
//------------------------------------------------
//添加货币表示符号(不同的国家,添加的符号不一样
a.applyPattern("\u00A4");
s = a.format(34);
System.err.println;
//------------------------------------------------
//-----------------------------------------------
//定义正负数模板,记得要用分号隔开
a.applyPattern("0.0;'@'-#.0");
s = a.format(33);
System.err.println;
s = a.format(-33);
System.err.println;
//-----------------------------------------------
}
}