public static void main(String[] args) {
// BigDecimal四舍五入
BigDecimal a = new BigDecimal("3.34543");
BigDecimal bigDecimal = a.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println(bigDecimal);
//向下取整,保留2位小数
String num = "2.345";
double floor = Math.floor(Double.valueOf(num));
String format = String.format("%.2f", floor);
System.out.println(format);
}
public BigDecimal bigDecimalToRound(BigDecimal bigDecimal, int newScale) {
return bigDecimal.setScale(newScale, BigDecimal.ROUND_HALF_UP);
}
public String stringToFloor(String str) {
return String.format("%.2f", Math.floor(Double.valueOf(str)));
}