- importjava.text.DecimalFormat;
-
- publicclassTestNumberFormat{
-
- publicstaticvoidmain(String[]args){
- doublepi=3.1415927;
-
- System.out.println(newDecimalFormat("0").format(pi));
-
- System.out.println(newDecimalFormat("0.00").format(pi));
-
- System.out.println(new DecimalFormat("00.000").format(pi));
-
- System.out.println(newDecimalFormat("#").format(pi));
-
- System.out.println(new DecimalFormat("#.##%").format(pi));
-
- longc=299792458;
-
- System.out.println(newDecimalFormat("#.#####E0").format(c));
-
- System.out.println(newDecimalFormat("00.####E0").format(c));
-
- System.out.println(newDecimalFormat(",###").format(c));
-
- System.out.println(newDecimalFormat("光速大小为每秒,###米。").format(c));
- }
- }