package com.jeeplus.modules.sg.overheadline.util;

import java.math.BigDecimal;

public class DoubleUtil {

    /**
     * 返回double保留两位小数点的值
     * @param num
     * @return
     */
    public static double round2(double num){
        return (double) Math.round(num * 100) / 100;
    }

    /**
     * 返回double类型 value1减去value2的准确值
     * @param value1
     * @param value2
     * @return
     */
    public static double sub(Double value1, Double value2) {
        BigDecimal b1 = new BigDecimal(Double.toString(value1));
        BigDecimal b2 = new BigDecimal(Double.toString(value2));
        return b1.subtract(b2).doubleValue();
    }

    /**
     * 返回double类型 获得value1加上value2的精确值
     * @param value1
     * @param value2
     * @return
     */
    public static double add(Double value1, Double value2) {
        BigDecimal b1 = new BigDecimal(Double.toString(value1));
        BigDecimal b2 = new BigDecimal(Double.toString(value2));
        return b1.add(b2).doubleValue();
    }

}
