您的位置:首页 > 编程语言 > Java开发

JAVA double类型数值,通过NumberFormat类取值的尝试

2015-12-08 16:03 501 查看
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(1); //设置小数点后保留的最大位数(四舍五入)
nf.setMaximumIntegerDigits(3);//设置整数部分保留的最大位数(从左往右舍弃)
nf.setMinimumFractionDigits(1); //设置小数点后最少保留的位数(如果是整数,会自动添加.0)
nf.setMinimumIntegerDigits(2);//设置整数部分最小位数(位数不足时会自动补0)
System.out.println("test:"+nf.format(test));


NumberFormat类的format(double value) 方法返回的值为String类型的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: