这里首先介绍如何使用DecimalFormat,给出一段代码如下:
[code]double d = Math.PI;
String pattern = "###.###";
DecimalFormat formatter = new DecimalFormat(pattern);
String hitRate = formatter.format(d);
assertTrue("3.142".equals(hitRate));[/code]
这里需要注意的是“四舍五入”
[code]double d = Math.PI;
String pattern = "###.###";
DecimalFormat formatter = new DecimalFormat(pattern);
String hitRate = formatter.format(d);
assertTrue("3.142".equals(hitRate));[/code]
这里需要注意的是“四舍五入”