Commit cca1b7ea authored by yanzg's avatar yanzg

修复bug

parent 35df541f
......@@ -24,6 +24,21 @@ public class CalcHelper {
return b1.add(b2).doubleValue();
}
/**
* 相加
*
* @param d1
* @param d2
* @return
*/
public static double addList(double d1, double... d2) {
double ret = d1;
for (double item : d2) {
ret = add(ret, item);
}
return ret;
}
/**
* 相减
*
......@@ -35,7 +50,21 @@ public class CalcHelper {
BigDecimal b1 = new BigDecimal(Double.toString(d1));
BigDecimal b2 = new BigDecimal(Double.toString(d2));
return b1.subtract(b2).doubleValue();
}
/**
* 相减
*
* @param d1
* @param d2
* @return
*/
public static double subList(double d1, double... d2) {
double ret = d1;
for (double item : d2) {
ret = sub(ret, item);
}
return ret;
}
/**
......@@ -49,7 +78,21 @@ public class CalcHelper {
BigDecimal b1 = new BigDecimal(Double.toString(d1));
BigDecimal b2 = new BigDecimal(Double.toString(d2));
return b1.multiply(b2).doubleValue();
}
/**
* 相乘
*
* @param d1
* @param d2
* @return
*/
public static double mulList(double d1, double... d2) {
double ret = d1;
for (double item : d2) {
ret = mul(ret, item);
}
return ret;
}
/**
......@@ -78,7 +121,59 @@ public class CalcHelper {
BigDecimal b1 = new BigDecimal(Double.toString(d1));
BigDecimal b2 = new BigDecimal(Double.toString(d2));
return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
/**
* 相除
*
* @param d1
* @param d2
* @return
*/
public static double divList(double d1, double... d2) {
double ret = d1;
for (double item : d2) {
ret = div(ret, item);
}
return ret;
}
/**
* 转换为金额
*
* @param from 来源数据
* @param scale 保留浮点数
* @param roundingMode 四舍五入类型
* @return 转换为金额
*/
public static double toMoney(double from, int scale, int roundingMode) {
return new BigDecimal(Double.toString(from))
.setScale(scale, roundingMode)
.doubleValue()
;
}
/**
* 转换为金额
*
* @param from 来源数据
* @return 转换为金额
*/
public static double toMoney(double from) {
return toMoney(from, 2, BigDecimal.ROUND_HALF_UP);
}
/**
* 判断是否相等
*
* @param d1
* @param d2
* @return
*/
public static boolean equals(double d1, double d2) {
BigDecimal b1 = new BigDecimal(Double.toString(d1));
BigDecimal b2 = new BigDecimal(Double.toString(d2));
return b1.equals(b2);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment