package com.sonic.lion.utils;

import java.math.BigDecimal;

public class MoneyUtils {


    /**
     * 单位转换,分转换成元
     *
     * @param cent (分)
     * @return BigDecimal (元)
     */
    public static BigDecimal centToDollar(Long cent) {
        if (null == cent)
            return null;

        return new BigDecimal(cent).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
    }

    /**
     * 计算手续费,四舍五入0位小数
     *
     * @param money
     * @param rate
     * @return
     */
    public static Long calculateFee(Long money, Double rate) {
        if (money == null || rate == null)
            return null;

        return new BigDecimal(money)
                .multiply(new BigDecimal(rate)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();

    }
}
