将字符串类型的指数整数(例如 "2.4490677E7"
)转换为整数字符串(例如 "24490677"
)的最佳/最快方法是什么)在Java中?
编辑:已知输入始终是整数。
我当前的建议如下(使用 Apache Commons 的 org.apache.commons.lang.math.NumberUtils
):
String input = "2.4490677E7";
String res = null;
Double d = NumberUtils.toDouble(input);
if (d != 0.0d) {
// we have a double number here
res = String.format("%d", d.intValue());
}
最佳答案
如果你需要不影响精度,那么你可以使用BigDecimal读取字符串,然后将其转换为int值
关于java - 如何将指数数字字符串转换为整数字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37188806/