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.hdl.sdk.hdl_sdk.utlis;
 
import android.content.Context;
import android.os.Build;
 
import java.math.BigDecimal;
 
/**
 * Created by JLChen on 2019/7/4
 */
public class HDLUtlis {
 
    /**
     * 将object转为Integer类型
     * @param object
     * @return
     */
    public static Integer getIntegerByObject(Object object){
        Integer in = null;
        if(object!=null){
            if(object instanceof Integer){
                in = (Integer)object;
            }else if(object instanceof String){
                in = Integer.parseInt((String)object);
            }else if(object instanceof Double){
                in = (int)((double)object);
            }else if(object instanceof Float){
                in = (int)((float)object);
            }else if(object instanceof BigDecimal){
                in = ((BigDecimal)object).intValue();
            }else if(object instanceof Long){
                in = ((Long)object).intValue();
            }
        }
        return in;
    }
 
 
}