mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
除数和被除数任意一个为0 会抛出Exception in thread "main" java.lang.ArithmeticException: / by zero 异常
This commit is contained in:
parent
1efa09d8ad
commit
055e429229
@ -747,12 +747,19 @@ public class NumberUtil {
|
|||||||
if (null == v1) {
|
if (null == v1) {
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
if(v1.compareTo(BigDecimal.ZERO)==0||v2.compareTo(BigDecimal.ZERO)==0){
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
if (scale < 0) {
|
if (scale < 0) {
|
||||||
scale = -scale;
|
scale = -scale;
|
||||||
}
|
}
|
||||||
return v1.divide(v2, scale, roundingMode);
|
return v1.divide(v2, scale, roundingMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(div(BigDecimal.ZERO,BigDecimal.ZERO));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 补充Math.ceilDiv() JDK8中添加了和Math.floorDiv()但却没有ceilDiv()
|
* 补充Math.ceilDiv() JDK8中添加了和Math.floorDiv()但却没有ceilDiv()
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user