package com.qimai.android.tools

import java.math.BigDecimal

/**
 *   created by wangwei   ON 2019-11-28  email:wangwei_5521@163.com
 *   @version 1.1.1
 *   @Description
 **/


// 加法运算
fun BigDecimal.add(d2: Double, retain: Int): Double {
    return add(BigDecimal(d2)).setScale(retain, BigDecimal.ROUND_HALF_UP).toDouble()
}

//减法
fun BigDecimal.sub(d2: Double, retain: Int): Double {
    return subtract(BigDecimal(d2)).setScale(
        retain,
        BigDecimal.ROUND_HALF_UP
    ).toDouble()
}


// 乘法运算
fun mul(d1: Double, d2: Double, decimalPoint: Int): Double =
    BigDecimal(d1).multiply(BigDecimal(d2)).setScale(decimalPoint, BigDecimal.ROUND_DOWN).toDouble()

// 除法运算
fun div(d1: Double, d2: Double, decimalPoint: Int): Double =
    BigDecimal(d1).divide(BigDecimal(d2)).setScale(
        decimalPoint,
        BigDecimal.ROUND_DOWN
    ).toDouble()