-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUtils.java
More file actions
40 lines (36 loc) · 1.2 KB
/
Utils.java
File metadata and controls
40 lines (36 loc) · 1.2 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
package com.utils;
public class Utils {
/**
* 比较两个数字的值是否相等,==比较的是值, 1 == 1.00 的结果是 true
* @param num
* @param obj
* @return
*/
public static boolean numValEqual(int num, Object obj){
if(obj == null){
return false;
}else{
try {
if (obj instanceof Integer) {
int value = ((Integer) obj).intValue();
return value == num;
} else if (obj instanceof String) {
String s = (String) obj;
return Double.parseDouble(s) == num;
} else if (obj instanceof Double) {
double d = ((Double) obj).doubleValue();
return d == num;
} else if (obj instanceof Float) {
float f = ((Float) obj).floatValue();
return f == num;
} else if (obj instanceof Long) {
long l = ((Long) obj).longValue();
return l == num;
}
}catch (Exception e){
return false;
}
}
return false;
}
}