package com.boman.common.core.utils.number;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.NumberFormat;

import static com.boman.common.core.utils.obj.ObjectUtils.*;

/**
 * @author shiqian
 * @date 2021年06月11日 10:00
 **/
public class NumberUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(NumberUtils.class);

    public static boolean gtZero(int input){
        return input > 0;
    }

    public static boolean ltZero(int input){
        return input < 0;
    }

    public static boolean eqZero(int input){
        return input == 0;
    }

    /**
     * 功能描述: 两个int相除，取百分比
     *
     * @param one one
     * @param another another
     * @return java.lang.String
     */
    public static String percent(Number one, Number another) {
        if (another == null || another.intValue() == 0) {
            return "0.00%";
        }

        double result = (double) one.longValue() / another.longValue();
        NumberFormat numberFormat = NumberFormat.getPercentInstance();
        //设置百分数精确度2即保留两位小数
        numberFormat.setMinimumFractionDigits(2);
        return numberFormat.format(result);
    }

}
