1.返回字符串类型,保留后两位:

public static String getRate(Object d) {
        return String.format("%.2f", d);
    }

 

 2.返回字符串类型,保留后两位:

public static String getRate1(Object d) {
        DecimalFormat df = new DecimalFormat();
        df.applyPattern("0.00");
        return df.format(d);
    }

 

3.返回double类型,保留后两位: 

//newScale为小数点位数
public
static Double roundValue(Double d, int newScale) { Double retValue = null; if (d != null) { BigDecimal bd = new BigDecimal(d); retValue = bd.setScale(newScale,BigDecimal.ROUND_HALF_UP).doubleValue(); } return retValue; }

 

相关文章:

  • 2022-12-23
  • 2021-05-24
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2021-12-29
  • 2020-03-30
  • 2022-12-23
相关资源
相似解决方案