java - 将字符串值转换为 int

标签 java integer typeconverter numberformatexception

如何将字符串值转换为int值?我得到number format exception .

String s = "20.00";
int i = (Integer.parseInt(s));
System.out.println(i);

结果应类似于 i=20 .

最佳答案

关于:

int i = (int) Double.parseDouble(s);

当然,“20.00”不是有效的整数格式。

关于java - 将字符串值转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19590262/

相关文章:

java - 如何在各个 JUnit 测试用例之间实现公共(public)数据共享

c++ - 将两个字符的字符串变量转换为十六进制

python - 为什么 (-3//2 = -2)

javascript - 将字符串javascript数组转换为整数javascript数组

java - 通过使用超过 1 个深度级别的 map 从 csv 转换为 json

c# - 自定义本地化 BooleanConverter

java - Spring中@Bean和Autowired有什么区别?

java - ArrayList 的 remove(object) 给出 IndexOutOfBoundsException

java - 如何在 HtmlUnit (java) 中禁用或指定重试次数?

java - ArrayIndexOutOfBoundsException、字符串、Int