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 怎样用字节数组在本地文件系统生成图像 关于volatile,到现在都理解不到位! 关于JAVA中图形界面的修改问题 关于output问题(初学者) run as java application 和run as java bean的区别!求教 哪位大虾解释下"各字节的带进位累加和"怎么理解? java的两个问题? 如何能够得到当前运行的JAVA应用程序路径?(高分) 请问如何用jdk命令编译java源文件?高分求救 关于socket使用setSoTimeout后出现的问题(服务器老是不间断的向客户端发送消息) 新手求解!关于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));