init
This commit is contained in:
53
ruoyi-xq/src/main/java/com/ruoyi/xq/util/CaiNumUtil.java
Normal file
53
ruoyi-xq/src/main/java/com/ruoyi/xq/util/CaiNumUtil.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.ruoyi.xq.util;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class CaiNumUtil {
|
||||
|
||||
/**
|
||||
* 向下取整计算金额
|
||||
* @param value
|
||||
* @param rate
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal coin(BigDecimal value, BigDecimal rate){
|
||||
if(value == null || rate == null){
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal decimal = NumberUtil.mul(value, rate);
|
||||
return decimal.setScale(0, RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
public static String rateToStr(BigDecimal rate){
|
||||
BigDecimal mul = NumberUtil.mul(rate, 100);
|
||||
return mul.intValue()+"%";
|
||||
}
|
||||
|
||||
public static BigDecimal memberDay(BigDecimal price, Integer days){
|
||||
BigDecimal div = NumberUtil.div(price, days, 2);
|
||||
if(div.compareTo(BigDecimal.ZERO) == 0){
|
||||
return new BigDecimal("0.01");
|
||||
}
|
||||
return div;
|
||||
}
|
||||
|
||||
public static BigDecimal diffRate(Long onlineTodayNum, Long onlineLastNum) {
|
||||
Long diff = onlineTodayNum - onlineLastNum;
|
||||
if(onlineLastNum == 0){
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return NumberUtil.div(diff,onlineLastNum,3);
|
||||
}
|
||||
|
||||
public static BigDecimal diffRate(BigDecimal onlineTodayNum, BigDecimal onlineLastNum) {
|
||||
BigDecimal diff = NumberUtil.sub(onlineTodayNum, onlineLastNum);
|
||||
if(onlineLastNum.compareTo(BigDecimal.ZERO) == 0){
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return NumberUtil.div(diff,onlineLastNum,3);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user