首页 > 编程语言 >java 如何解决String类型转成int类型报错(因长度问题)?

java 如何解决String类型转成int类型报错(因长度问题)?

时间:2023-03-28 16:47:16浏览次数:32  
标签:BigInteger java String int valueOf other 报错

原因:“int最大长度是11位

使用 Integer.valueOf(uuid),一旦uuid超过11位就会报错。

如果想要计算怎么办?

第一种:是用长整型 String.valueOf(Long.parseLong(fileId) + 1)

第二种:使用BigInteger,java中提供了Big--这一类,既可以将普通数字转化为大数字

BigInteger a=BigInteger.valueOf(100);

常用方法如下

BigInteger add(BigInteger other) 加
BigInteger subtract(BigInteger other)减
BigInteger multiply(BigInteger other)乘
BigInteger divide(BigInteger other)除

标签:BigInteger,java,String,int,valueOf,other,报错
From: https://www.cnblogs.com/dongfangzhaoyue/p/17265780.html

相关文章