2023-10-08 18:44:32 +08:00
|
|
|
|
package com.zhgd.xmgl.util;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
|
|
|
|
|
|
|
public class NumberUtils {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 除以
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param b1
|
|
|
|
|
|
* @param b2
|
|
|
|
|
|
* @param scale
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2023-12-14 14:15:14 +08:00
|
|
|
|
public static Double div(Double b1, Double b2, Integer scale) {
|
2023-10-08 18:44:32 +08:00
|
|
|
|
if (b1 == null || b2 == null || b2.equals(0D)) {
|
|
|
|
|
|
return 0D;
|
|
|
|
|
|
}
|
|
|
|
|
|
return NumberUtil.round(b1 / b2, scale).doubleValue();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-14 14:15:14 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 大于等于
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static boolean ge(Double b1, Double b2) {
|
|
|
|
|
|
return b1 != null && b2 != null && b1 >= b2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 小于等于
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static boolean le(Double b1, Double b2) {
|
|
|
|
|
|
return b1 != null && b2 != null && b1 <= b2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-27 17:45:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* description: 使用 String.format 格式化数字,实现左侧补 0
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param num 需要格式化的数字
|
|
|
|
|
|
* @param digit 生成字符串长度(保留数字位数)
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
* @version v1.0
|
|
|
|
|
|
* @author w
|
|
|
|
|
|
* @date 2019年7月19日 下午2:14:31
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String fillZero(int num, int digit) {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 0:表示前面补0
|
|
|
|
|
|
* digit:表示保留数字位数
|
|
|
|
|
|
* d:表示参数为正数类型
|
|
|
|
|
|
*/
|
|
|
|
|
|
return String.format("%0" + digit + "d", num);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-08 18:44:32 +08:00
|
|
|
|
}
|