首页 > 代码库 > 两个Long类型相乘溢出怎么解决

两个Long类型相乘溢出怎么解决

public static void main(String[] args) throws Exception {        long a = Long.MAX_VALUE;        long b = Long.MAX_VALUE;        BigDecimal ba = new BigDecimal(String.valueOf(a));        BigDecimal bb = new BigDecimal(String.valueOf(b));        BigDecimal bc = ba.multiply(bb);        System.out.println(String.valueOf(a));        System.out.println(String.valueOf(b));        System.out.println(bc);    }

9223372036854775807
9223372036854775807
85070591730234615847396907784232501249