package com.bonus.common.biz.utils;

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

public class MathUtil {

    public static BigDecimal calculatePercentage(int num1, int num2) {
        if (num2 == 0) {
            throw new ArithmeticException("除数不能为0");
        }
        BigDecimal bdNum1 = new BigDecimal(num1);
        BigDecimal bdNum2 = new BigDecimal(num2);
        BigDecimal result = bdNum1.divide(bdNum2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
        return result.setScale(2, RoundingMode.HALF_UP);
    }

}
