Double精度问题【很基础的难题】 Double d = 120.00D;System.out.println(d);//输出结果:120.0//================================String s="123";Double d=Double.valueOf(s);System.out.println(d);//输出结果:123.0如果现在必须要两位小数(例如:12:00)如何处理?求多种方法!NumberFormat,strictfp等等! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 最后一句改成:System.out.println(new DecimalFormat("#.00").format(d)); DecimalFormat nf = new DecimalFormat(".00"); String s="123"; Double d=Double.valueOf(s); System.out.println(nf.format(d)); System.out.printf("%.2f\n", d);如果要转成StringString s = String.format("%.2f", d); DecimalFormat nf = new DecimalFormat(".00"); String s="123"; Double d=Double.valueOf(s); System.out.println(nf.format(d)); 朋友的问题,要求返回一个两位小数的double类型,而不是string double没有所谓2位小数的概念。你可以將某一double格式化成具体的精度展示方式,但不能指定某一个double在一个scale下计算。如果需要使用精度计算,请使用BigDecimal 用jxl将数据从数据库导出到excel中遇到write问题 GUI显示进度条 java 如何检查两个图片是否一致。 注意:ListService.java使用了未经检查或不安全的操作 求助!Applet运行的问题 新手问题,麻烦大家帮忙解释一下,谢谢。 UUID在高并发下出现重复?? 帮忙改一下小代码 刚过了SCJP,来散分,大家来捧场啊!!! web项目部署到阿里云linux服务器后,连接mysql出现问题 新手求解!关于Scanner 这程序伤不起啊
System.out.println(new DecimalFormat("#.00").format(d));
DecimalFormat nf = new DecimalFormat(".00");
String s="123";
Double d=Double.valueOf(s);
System.out.println(nf.format(d));
如果要转成String
String s = String.format("%.2f", d);
String s="123";
Double d=Double.valueOf(s);
System.out.println(nf.format(d));