Double类型保留小数的n种方法

来源:互联网 发布:写jquery必须会js么 编辑:程序博客网 时间:2024/06/06 01:44

类DecimalFormat

1、

import java.text.DecimalFormat;public class ssDouble {    public static void main(String[] args) {        DecimalFormat df1=new DecimalFormat("#####.##");        DecimalFormat df2=new DecimalFormat("0000.0000");        double d1=123456.11923423;        double d2=1.11;        System.out.println(df1.format(d1)+"  "+df1.format(d2));        System.out.println(df2.format(d1)+"  "+df2.format(d2));    }}

输出:
123456.12 1.11
123456.1192 0001.1100

0 0