public class MoneyUtil {
public static double fenToYuan(Integer fen) {
if (fen == null) {
return 0.0;
}
return BigDecimal.valueOf(fen).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
}
public static BigDecimal fenToYuan(BigDecimal fen) {
if (fen == null) {
return BigDecimal.ZERO;
}
return fen.divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
}
public static BigDecimal fenToYuanInt(Integer fen) {
if (fen == null) {
return BigDecimal.ZERO;
}
return BigDecimal.valueOf(fen).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
}
public static int yuanToFen(Double yuan) {
if (yuan == null) {
return 0;
}
return BigDecimal.valueOf(yuan).multiply(new BigDecimal(100)).intValue();
}
public static BigDecimal yuanToFen(BigDecimal yuan) {
if (yuan == null) {
return BigDecimal.ZERO;
}
return yuan.multiply(new BigDecimal(100));
}
public static Double getTwo(Double d) {
if (d != null && d != 0) {
BigDecimal b = new BigDecimal(d);
return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
} else {
return 0.0;
}
}
public static Double getTwo(BigDecimal d) {
if (d != null) {
return d.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
} else {
return 0.0;
}
}
public static Double getNine(Double d, int type) {
String s = d.toString();
String[] split = s.split("\\.");
if (split[1].length() >= 2) {
if (Integer.valueOf(split[1].charAt(1)) == '9') {
BigDecimal bg = new BigDecimal(d);
double v = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return v;
}
}
Double a = d;
if (type == 1) {
a = d - 0.1;
}
String s1 = a.toString();
String[] split1 = s1.split("\\.");
String c = split1[0] + "." + split1[1].charAt(0);
Double aDouble = Double.valueOf(c);
BigDecimal bg = new BigDecimal(aDouble + 0.09);
double d3 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return d3;
}
}