gpt4 book ai didi

java - 如何在 Java 中将非常大的字符串转换为数字

转载 作者:行者123 更新时间:2023-12-05 08:15:08 25 4
gpt4 key购买 nike

你好,我有一个像这样的大字符串:

"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"

我想把这个字符串转换成长字符串。但是我失败了。我做了:

Long.parseLong(longString);

但是我得到一个错误:

java.lang.NumberFormatException: For input string: "99999999.......

有什么办法可以避免这种情况吗?

最佳答案

使用BigInteger像这样上课:

 BigInteger number = new BigInteger(longString);

关于java - 如何在 Java 中将非常大的字符串转换为数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12967201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com