package com.sckw.payment.model.vo.res;

import com.sckw.core.model.constant.NumberConstant;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Objects;

/**
 * 金额转换
 *
 * @author xucaiqin
 * @date 2023-08-28 18:06:18
 */
public interface MoneyChange {
    /**
     * 元转分
     *
     * @param big
     * @return
     */
    default Long bigMoney(BigDecimal big) {
        if (Objects.isNull(big)) {
            return 0L;
        }
        BigDecimal divide = big.multiply(new BigDecimal("100"));
        return divide.longValueExact();
    }

    /**
     * 分转元
     *
     * @param big
     * @return
     */
    default BigDecimal smallMoney(BigDecimal big) {
        if (Objects.isNull(big)) {
            return NumberConstant.ZERO_TWO;
        }
        return big.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
    }

}
