Skip to content

Commit f624a95

Browse files
try2 (#182)
try2 (#182)
1 parent bdb6a97 commit f624a95

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

  • src/main/java/com/github/hcsp/datatype

src/main/java/com/github/hcsp/datatype/Cast.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,52 @@ public class Cast {
44
// Cast an int to byte
55
// 将int类型转换成byte
66
public static byte int2byte(int i) {
7-
return i;
7+
return (byte) i;
88
}
99

1010
// Cast an int to short
1111
// 将int类型转换成short
1212
public static short int2short(int i) {
13-
return i;
13+
return (short) i;
1414
}
1515

1616
// Cast an int to char
1717
// 将int类型转换成char
1818
public static char int2char(int i) {
19-
return i;
19+
return (char)i;
2020
}
2121

2222
// Cast an int to String, e.g. 123 -> "123"
2323
// 将一个整数转换为字符串,例如,将123转换成字符串"123"
2424
public static String int2String(int i) {
25-
return i;
25+
String s = Integer.toString(i);
26+
return s;
2627
}
2728

2829
// Cast an String to int, e.g. "123" -> 123
2930
// 将一个字符串转换成整数,例如,将字符串"123"转换成整数123
3031
public static int string2int(String s) {
31-
return s;
32+
int n = Integer.parseInt(s);
33+
return n;
3234
}
3335

3436
// Cast an String to double, e.g. "1.23" -> 1.23
3537
// 将一个字符串转换成double类型,例如,将字符串"1.23"转换成1.23
3638
public static double string2double(String s) {
37-
return s;
39+
double a=Double.parseDouble(s);
40+
return a;
3841
}
3942

4043
// Cast an Long to int
4144
// 将Long类型转换成int
4245
public static int Long2int(Long l) {
43-
return l;
46+
int c= new Long(l).intValue();
47+
return c;
4448
}
4549

4650
// Cast an Double to long
4751
// 将Double类型转换成long
4852
public static long double2Long(Double d) {
49-
return d;
53+
return new Double(d).longValue();
5054
}
5155
}

0 commit comments

Comments
 (0)