-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
类型转换 #323
base: master
Are you sure you want to change the base?
类型转换 #323
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,48 +4,48 @@ public class Cast { | |
// Cast an int to byte | ||
// 将int类型转换成byte | ||
public static byte int2byte(int i) { | ||
return i; | ||
return (byte)i; | ||
} | ||
|
||
// Cast an int to short | ||
// 将int类型转换成short | ||
public static short int2short(int i) { | ||
return i; | ||
return (short)i; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
// Cast an int to char | ||
// 将int类型转换成char | ||
public static char int2char(int i) { | ||
return i; | ||
return (char)i; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
// Cast an int to String, e.g. 123 -> "123" | ||
// 将一个整数转换为字符串,例如,将123转换成字符串"123" | ||
public static String int2String(int i) { | ||
return i; | ||
return String.valueOf(i) ; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
// Cast an String to int, e.g. "123" -> 123 | ||
// 将一个字符串转换成整数,例如,将字符串"123"转换成整数123 | ||
public static int string2int(String s) { | ||
return s; | ||
return Integer.parseInt(s); | ||
} | ||
|
||
// Cast an String to double, e.g. "1.23" -> 1.23 | ||
// 将一个字符串转换成double类型,例如,将字符串"1.23"转换成1.23 | ||
public static double string2double(String s) { | ||
return s; | ||
return Double.parseDouble(s); | ||
} | ||
|
||
// Cast an Long to int | ||
// 将Long类型转换成int | ||
public static int Long2int(Long l) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return l; | ||
return Math.toIntExact(l); | ||
} | ||
|
||
// Cast an Double to long | ||
// 将Double类型转换成long | ||
public static long double2Long(Double d) { | ||
return d; | ||
return Long.parseLong(String.valueOf(d)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
类型转换后应有空格。