60 lines
1.7 KiB
Java
60 lines
1.7 KiB
Java
package com.ruoyi.cai.util;
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
import lombok.Data;
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTabJc;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
|
|
public class CaiNumUtil {
|
|
|
|
/**
|
|
* 向下取整计算金额
|
|
* @param value
|
|
* @param rate
|
|
* @return
|
|
*/
|
|
public static Long coin(Long value, BigDecimal rate){
|
|
if(value == null || rate == null){
|
|
return 0L;
|
|
}
|
|
BigDecimal decimal = NumberUtil.mul(value, rate);
|
|
return decimal.setScale(0, RoundingMode.DOWN).longValue();
|
|
}
|
|
|
|
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 void main(String[] args) {
|
|
System.out.println(memberDay(BigDecimal.valueOf(20), 3220));
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|