在Java中將指數整數字符串類型(例如"2.4490677E7"
)轉換爲整數字符串(例如"24490677"
)的最佳/最快方法是什麼?如何將指數數字字符串轉換爲整數字符串
編輯:輸入已知總是一個整數。
我目前的建議如下(使用org.apache.commons.lang.math.NumberUtils
來自Apache的百科全書):
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());
}
有什麼問題呢? – Amit
2.4112E2 *轉換*的結果應該是什麼? –
如果您需要精確度不變,那麼您可以使用BigDecimal讀取字符串,然後將其轉換爲int值。 –