/** * 取小数点后两位,如果是整数,会小数点后加上0,再输出(如 1,输出1.0) * @param doubleNum * @return */ public static double cullNum(double doubleNum){ BigDecimal bd = new BigDecimal(doubleNum); bd = bd.setScale(2,BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } /** * 取小数点后 digitLen 位 * @return */ public static double cullNum(double doubleNum,int digitLen){ BigDecimal bd = new BigDecimal(doubleNum); bd = bd.setScale(digitLen,BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } /** * 将double型不以科学计数表示并转化为String类型 * * @param freight * * @return * @throws Exception */ public static String getDoubleToString(double num, String pattern) { if(pattern == null || "".equals(pattern)){ pattern = "0.00"; } DecimalFormat decimalFormat = new DecimalFormat(pattern); return decimalFormat.format(num); }