有一个小数,23.536678,我怎么才能把它控制在23.536呢?就是不论是23.536678还是23.5我都要保留小数点后3位,请问哪位大侠能告诉小弟,谢谢了!:)

解决方案 »

  1.   

    (1)
    import java.text.*;DecimalFormat myFormatter = new DecimalFormat("####.#");
    myFormatter.format(double); //注意,这句整体作为String 用
    (2)
    private double roundDouble(double val, int precision) {
    double factor = Math.pow(10, precision);
    return Math.floor(val * factor + 0.5) / factor;
    }precision为小数点后保留的位数,如果是两位就是2。
    (3)
    用substring实现
      

  2.   

    to: masse(当午)
      谢谢你,这就给你分!:)