假设我们要用四舍五入法保留两位小数
public class Main{
public static void main(String[] args){
double abc = 4.015;// we would like to get the result 4.02
System.out.println(new java.math.BigDecimal(Double.toString(abc)).setScale(2, java.math.BigDecimal.ROUND_HALF_UP).doubleValue());
}
}