package cn.gyee.tamplate.util; import java.math.BigDecimal; /** * @ClassName : DoubleUtils * @Author : xieshengjie * @Date: 2021/3/6 17:48 * @Description : 对单列统计过滤null */ public class DoubleUtils { public static Double ifNullSet0(Double in) { if (in != null) { return in; } return 0.0; } public static Integer ifNullSet0(Integer in) { if (in != null) { return in; } return 0; } public static Double sum(Double ...in){ Double result = 0.0; for (int i = 0; i < in.length; i++){ result = result+(ifNullSet0(in[i])); } return result; } public static String hb(String ...in){ String result = ""; for (int i = 0; i < in.length; i++){ result = result+in[i]; } return result; } public static Integer sum(Integer ...in) { Integer result = 0; for (int i = 0; i < in.length; i++){ result = result+(ifNullSet0(in[i])); } return result; } public static Double max(Double ...in){ Double result = 0.0; for (int i = 0; i < in.length; i++){ if (resultifNullSet0(in[i])){ result=ifNullSet0(in[i]); } } return result; } public static Double ave(Double ...in){ if(in.length==0){ return 0.0; }else{ return sum(in)/in.length; } } /** * * @param numA 数字A * @param numB 数字B * @param operate 运算符 * @return */ public static double GetResult(double numA, double numB, String operate){ double res = 0; BigDecimal bigA = new BigDecimal(Double.toString(numA)); BigDecimal bigB = new BigDecimal(Double.toString(numB)); switch (operate) { case "+": res = bigA.add(bigB).doubleValue(); break; case "-": res = bigA.subtract(bigB).doubleValue(); break; case "*": res = bigA.multiply(bigB).doubleValue(); break; case "/": res = bigA.divide(bigB).doubleValue(); break; default : System.out.println("运算符不合法~"); break; } return res; } }