package com.ningdatech.carapi.common.util;

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

import cn.hutool.core.util.NumberUtil;

/**
 * <p>
 * BizUtils
 * </p>
 *
 * @author WendyYang
 * @since 17:34 2022/12/5
 */
public class BizUtils {

    public static String percent(Long numerator, Long denominator) {
        if (numerator == null || numerator == 0) {
            return "0%";
        }
        if (denominator == null || denominator == 0 ){
            return NumberUtil.div(numerator, BigDecimal.valueOf(1)).multiply(BigDecimal.valueOf(100))
                    .setScale(2, RoundingMode.HALF_UP) + "%";
        }
        return NumberUtil.div(numerator, denominator).multiply(BigDecimal.valueOf(100))
                .setScale(2, RoundingMode.HALF_UP) + "%";
    }


    public static void main(String[] args) {
        System.out.println(percent(-1L, 0L));
    }
}
