double money =  1.365;
我希望保留两位以后是1.37 int roundingMode = 4;
BigDecimal bd = new BigDecimal(money);
bd = bd.setScale(scale, roundingMode);
return bd;
这种方式不好使啊!NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(scale);
System.out.println(nf.format(money));
这种也完蛋!

解决方案 »

  1.   

    double money = 1.365;
    String result = String.format("%.2f", money);
    System.out.println(result);
      

  2.   


    private static BigDecimal getDecimal(double money, int scale) {
    //等价于:String result = String.format("%.2f", money);
    BigDecimal bd = new BigDecimal(""+money);//这里得用字符串,而不能用double
    bd = bd.setScale(scale, BigDecimal.ROUND_HALF_UP);
      return bd;
    }