package com.xty.common.util

import java.math.BigDecimal
import java.text.DecimalFormat

object NumUtils {

    fun divide(valueOne: Int, valueTwo: Int, scale: Int): Double {
        if (scale < 0) {
            throw IllegalArgumentException("The scale must be a positive integer or zero")
        }
        val b1 = BigDecimal(java.lang.Double.toString(valueOne.toDouble()))
        val b2 = BigDecimal(java.lang.Double.toString(valueTwo.toDouble()))
        return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).toDouble()
    }

    fun formatter(value:Double,formatter:String):String{

        var mFormat = DecimalFormat(formatter)
        return mFormat.format(value).toString()
    }

    fun format2(value:Double):String {
        val df = DecimalFormat("#.00")
        return  df.format(value)
    }

    fun format3(value:Double):Double {
        val bg = BigDecimal(value)
        return  bg.setScale(2,BigDecimal.ROUND_HALF_UP).toDouble()

    }


}