轉(zhuǎn)載于http://my.oschina.net/se77en/blog/41869 一 java.text.DecimalFormat df = new java.text.DecimalFormat("#0.##"); double d=3.14159; System.out.println(df.format(d)); Ⅱ java.math.BigDecimal bd = new java.math.BigDecimal("3.14159265"); bd = bd.setScale(2,BigDecimal.ROUND_HALF_UP); Ⅲ class Test{ public static void main(String se77en[]){ double ret = convert(3.14159); System.out.println(ret); } static double convert(double value){ long l1 = Math.round(value*100); //四舍五入 double ret = l1/100.0; //注意:使用100.0而不是100 return ret; } } Ⅳ double d = 3.14159; d = (double)((int)(d*100+0.5))/100;
發(fā)表評論