MathUtils.java
1.3 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
40
41
42
43
44
45
46
47
48
49
50
51
package com.drp.mobliemall.utils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
/**
* Created by Administrator on 2015/1/21.
* 数学运算帮助类
*/
public class MathUtils {
/**
* 将 doule 值精确到两位
* @param value
* @return
*/
public static double convertTwoBit(double value){
long l1 = Math.round(value * 100); //四舍五入
double ret = l1/100.0; //注意:使用 100.0 而不是 100
if(ret<=0)
ret = 0.00;
return ret;
}
public static double formatData(double value){
DecimalFormat df = new DecimalFormat("##.00");
return Double.parseDouble(df.format(value));
}
public static BigDecimal formatDataForBackBigDecimal(double value){
if(value > 0) {
DecimalFormat df = new DecimalFormat("##.00");
return new BigDecimal(df.format(value));
}
return new BigDecimal(0.00);
}
public static String formatDataForBackString(double value){
DecimalFormat df = new DecimalFormat("##.00");
return df.format(value).toString();
}
public static double getTotalAmount(double count,double price){
DecimalFormat df = new DecimalFormat("##.00");
return count*price;
}
}