在Java中,没有直接的官方方法来实现将包含逗号的数字字符串(如“1,890”)转换为整数(1890)的转换,但你可以使用以下代码来实现:

String number = "1,890";
number = number.replace(",", ""); // 去除逗号
int result = Integer.parseInt(number);
System.out.println(result);

此代码首先使用replace()方法去除逗号,然后使用Integer.parseInt()方法将字符串转换为整数。最后,使用System.out.println()方法打印结果。


原文地址: https://www.cveoy.top/t/topic/qxxg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录