object Arith {
fun add(value1: Double, value2: Double): Double {
val b1 = BigDecimal(java.lang.Double.valueOf(value1))
val b2 = BigDecimal(java.lang.Double.valueOf(value2))
return b1.add(b2).toDouble()
}
fun sub(value1: Double, value2: Double): Double {
val b1 = BigDecimal(java.lang.Double.valueOf(value1))
val b2 = BigDecimal(java.lang.Double.valueOf(value2))
return b1.subtract(b2).toDouble()
}
fun mul(value1: Double, value2: Double): Double {
val b1 = BigDecimal(java.lang.Double.valueOf(value1))
val b2 = BigDecimal(java.lang.Double.valueOf(value2))
return b1.multiply(b2).toDouble()
}
@Throws(IllegalAccessException::class)
fun div(value1: Double, value2: Double, scale: Int): Double {
if (scale < 0) {
throw IllegalAccessException("精确度不能小于0")
}
val b1 = BigDecimal(value1.toString())
val b2 = BigDecimal(value2.toString())
return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).toDouble()
}
}