haijiang
2018-06-25 586f13d3aa93fc3fdfed65021b1a17a17acf3321
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.moral.andbrickslib.utils;
 
import java.math.BigDecimal;
import java.text.DecimalFormat;
 
/**
 * 数字操作工具类
 * Created by haijiang on 2017/4/24.
 */
 
public class NumberUtils {
    public static int getIntValue(String strTemp) {
        int nRet = 0;
 
        try {
            if (strTemp == null) {
                return nRet;
            }
 
            nRet = Integer.parseInt(strTemp);
        } catch (Exception ex) {
            nRet = 0;
        }
 
        return nRet;
    }
    /**
     * 大数据金额保留小数位
     * @param strTemp
     * @param count
     * @return
     */
    public static double getBigDecimalValue(String strTemp,int count) {
        BigDecimal temp = new BigDecimal(strTemp);
        double doubleNum = temp.setScale(count,
                BigDecimal.ROUND_HALF_UP)
                .doubleValue();
        return doubleNum;
    }
 
    public static String get2DecimalValue(double strTemp) {
        DecimalFormat df = new DecimalFormat("0.00");
        return df.format(strTemp);
    }
 
    /**
     * 大数据金额保留小数位
     * @param strTemp
     * @return
     */
    public static float getFloatDecimalValue(float strTemp) {
        BigDecimal temp = new BigDecimal(strTemp);
        float floatNum = temp.setScale(2,
                BigDecimal.ROUND_HALF_UP)
                .floatValue();
        return floatNum;
    }
 
    public static long getLongValue(String strTemp) {
        long nRet = 0;
 
        try {
            if (strTemp == null) {
                return nRet;
            }
 
            nRet = Long.parseLong(strTemp);
        } catch (Exception ex) {
            nRet = 0;
        }
 
        return nRet;
    }
 
    public static double getDoubleValue(String strTemp) {
        double nRet = 0.0;
 
        try {
            nRet = Double.valueOf(strTemp);
        } catch (Exception ex) {
        }
 
        return nRet;
    }
 
    public static float getFloatValue(String strTemp) {
        float nRet = 0.0f;
        try {
            nRet = Float.parseFloat(strTemp);
        } catch (Exception ex) {
            nRet = 0.0f;
        }
        return nRet;
    }
}