将小数转为折扣形式

String discount = “小数的折扣”;

BigDecimal b2 = new BigDecimal(discount);
BigDecimal b1 = new BigDecimal(100);
if (b2 != null) {
BigDecimal b3 = b1.multiply(b2);
if (b3 != null) {
String bg = “”;
String s1 = b3.setScale(0, RoundingMode.CEILING) + “”;
String s2 = s1.substring(s1.length() - 1,s1.length());
if (“0”.equals(s2)) {
bg = s1.substring(0, s1.length() - 1);
} else {
bg = s1;
}
//返回折扣的逻辑
}
}

你可能感兴趣的:(java)