package cn.hp.test;
import java.text.DecimalFormat;
public class demo04 {
public static void main(String[] args) throws Exception {
//12.3456 要求保留两位
double d = 12.3456;
DecimalFormat df = new DecimalFormat("0.00");
//格式化
String s = df.format(d);
System.out.println("s = "+s);
//解析字符串
Number n = df.parse("123.23");
double v = n.doubleValue();
System.out.println("v = " + v);
double money = 213212.4654;
DecimalFormat df2 = new DecimalFormat("000,000.00");
String s2 = df2.format(money);
System.out.println("s2 = " + s2);
}
}
暑期编程PK赛
得CSDN机械键盘等精美礼品!