package com.ghy.common.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 处理金额工具类
 */
public class MoneyUtil {

    public static boolean equals(BigDecimal a, BigDecimal b) {
        return a.compareTo(b) == 0;
    }

    /**
     * a > b
     */
    public static boolean gt(BigDecimal a, BigDecimal b) {
        return a.compareTo(b) > 0;
    }

    /**
     * a >= b
     */
    public static boolean gte(BigDecimal a, BigDecimal b) {
        return a.compareTo(b) >= 0;
    }

    /**
     * a < b
     */
    public static boolean lt(BigDecimal a, BigDecimal b) {
        return a.compareTo(b) < 0;
    }

    /**
     * a <= b
     */
    public static boolean lte(BigDecimal a, BigDecimal b) {
        return a.compareTo(b) <= 0;
    }

    /**
     * a == 0
     */
    public static boolean equals0(BigDecimal a) {
        return equals(a, BigDecimal.ZERO);
    }

    /**
     * a > 0
     */
    public static boolean gt0(BigDecimal a) {
        return gt(a, BigDecimal.ZERO);
    }

    /**
     * a >= 0
     */
    public static boolean gte0(BigDecimal a) {
        return gte(a, BigDecimal.ZERO);
    }

    /**
     * a < 0
     */
    public static boolean lt0(BigDecimal a) {
        return lt(a, BigDecimal.ZERO);
    }

    /**
     * a <= 0
     */
    public static boolean lte0(BigDecimal a) {
        return lte(a, BigDecimal.ZERO);
    }

    public static String toS(BigDecimal money) {
        return money.setScale(2, RoundingMode.UNNECESSARY).toString();
    }
}
