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

发布时间 2023-03-28 16:43:22作者: 东方昭月

原因:“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)除