package com.sckw.payment.utils;

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

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

/**
 * @author xucaiqin
 * @date 2026-03-30 10:10:38
 */
public class MoneyUtil {
    /**
     * 元转分
     *
     * @param big
     * @return
     */
    public static Long bigMoney(BigDecimal big) {
        if (Objects.isNull(big)) {
            return 0L;
        }
        BigDecimal divide = big.multiply(new BigDecimal("100"));
        return divide.longValueExact();
    }

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