parent
7e5c29cc4d
commit
9a1355a379
@ -1,7 +0,0 @@
|
|||||||
package com.internal;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("Hello world!");
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.internal.util;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public class BigDecimalUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param v1
|
||||||
|
* @param v2
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static double add(double v1,double v2){
|
||||||
|
BigDecimal b1 = BigDecimal.valueOf(v1);
|
||||||
|
BigDecimal b2 = BigDecimal.valueOf(v2);
|
||||||
|
|
||||||
|
return b1.add(b2).doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 除法
|
||||||
|
* @param v1
|
||||||
|
* @param v2
|
||||||
|
* @return
|
||||||
|
* @throws IllegalAccessException
|
||||||
|
*/
|
||||||
|
public static double divide(int v1,int v2) throws IllegalAccessException {
|
||||||
|
if(v2 <= 0){
|
||||||
|
throw new IllegalAccessException("除数异常");
|
||||||
|
}
|
||||||
|
BigDecimal b1 = BigDecimal.valueOf(v1);
|
||||||
|
BigDecimal b2 = BigDecimal.valueOf(v2);
|
||||||
|
return b1.divide(b2,2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double subtract(double v1,double v2) {
|
||||||
|
BigDecimal b1 = BigDecimal.valueOf(v1);
|
||||||
|
BigDecimal b2 = BigDecimal.valueOf(v2);
|
||||||
|
return b1.subtract(b2).doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static double multiply(double v1,double v2) {
|
||||||
|
BigDecimal b1 = BigDecimal.valueOf(v1);
|
||||||
|
BigDecimal b2 = BigDecimal.valueOf(v2);
|
||||||
|
return b1.multiply(b2).doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue