如何在 Java 中将非常大的字符串转换为数字 [英] How Do I convert very big String to number in Java
问题描述
我有一个像这样的大字符串:
Hi I have a big string like this :
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
我希望将此字符串转换为长字符串.但我失败了.我做到了:
I wish to convert this string to long. But I failed. I did:
Long.parseLong(longString);
但我收到一个错误:
java.lang.NumberFormatException: For input string: "99999999.......
有什么办法可以避免这种情况吗?
Are there any way to avoid this?
推荐答案
使用 BigInteger 类如下:
BigInteger number = new BigInteger(longString);
这篇关于如何在 Java 中将非常大的字符串转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!