NumberUtils.java
1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.erry.iclear.dateInterface.util;
import java.math.BigDecimal;
/**
* 数值处理类
* mt
* 2021年8月5日16:31:02
*/
public class NumberUtils {
/**
* 保留两位小数(四舍五入),0.00之后有数字全部保留位0.01
* @param bdForMat
* @return
*/
public static BigDecimal bigDecimalFormat(BigDecimal bdForMat,int num){
if(bdForMat != null){
bdForMat = bdForMat.setScale(num, BigDecimal.ROUND_HALF_UP);
if(bdForMat.compareTo(BigDecimal.ZERO) == 0){
bdForMat = new BigDecimal(0.01).setScale(num,BigDecimal.ROUND_HALF_UP);
}
return bdForMat;
}
return null;
}
/**
* 将Bigdecimal转换成Integer
* @param bigDecimal
* @return
*/
public static Integer bigDecimalToIntger(BigDecimal bigDecimal){
Integer integer = new Integer(0);
if(bigDecimal != null){
integer = bigDecimal.intValue();
}
return integer;
}
}