java中double四舍五入并设置小数点位数的问题

//方案一:  
get_double = (double)(Math.round(result_value*100)/100.0)   

//方案二:  
DecimalFormat df = new DecimalFormat("#.##");    
get_double = Double.ParseDouble(df.format(result_value));  

//方案三:  
get_double = Double.ParseDouble(String.format("%.2f",result_value));  

//方案四:  
BigDecimal bd = new BigDecimalresult_value();  
BigDecimal  bd2 = bd.setScale(2,BigDecimal  .ROUND_HALF_UP);  
get_double = Double.ParseDouble(bd2.ToString());  

posted on 2015-05-09 16:43  MrCharles在cnblogs  阅读(68)  评论(0编辑  收藏  举报

导航