float四舍五入保留两位小数
/*** float四舍五入保留两位小数* */public static float formatDecimal(float n) {return (Math.round(n * 100)) / 100f;}
double四舍五入保留两位小数
/*** double四舍五入保留两位小数* */public static double formatDecimal(double n) {return (Math.round(n * 100)) / 100d;}
BigDecimal向上取整
/*** BigDecimal向上取整* */public static BigDecimal formatUpRounding(BigDecimal b) {return b.setScale(0, BigDecimal.ROUND_UP);}
BigDecimal向下取整
/*** BigDecimal向下取整* */public static BigDecimal formatDownRounding(BigDecimal b) {return b.setScale(0, BigDecimal.ROUND_DOWN);}
BigDecimal四舍五入取整
/*** BigDecimal四舍五入取整* */public static BigDecimal formatRounding(BigDecimal b) {return b.setScale(0, BigDecimal.ROUND_HALF_EVEN);}
BigDecimal保留两位小数 转换成float
/*** BigDecimal四舍五入保留两位小数 转float* */public static float toFloat(BigDecimal b){return b.setScale(2).floatValue();}
BigDecimal转换成String
/*** BigDecimal to String* */public static String toString(BigDecimal b) {return b.toPlainString();}