c ++或java中的数据类型,用于保存20位整数 [英] Data type in c++ or java for holding 20 digit integer
本文介绍了c ++或java中的数据类型,用于保存20位整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java或C ++中是否有任何数据类型可以容纳20位数或更多的整数值?
Is there any data type available in Java or C++ which can hold integer values of 20 digits or more? The long long data type can hold only till 18 digits.
推荐答案
Java特定:
您正在查找 BigInteger
You are looking for BigInteger
不可变任意精度整数。所有操作的行为好像BigIntegers以二进制补码表示法(如Java的原始整数类型)表示。
Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's primitive integer types)
For ex:
BigInteger bint = new BigInteger("1234567856656569");
BigInteger bint2 = new BigInteger("1234556567856656569");
System.out.println(bint2.intValue()-bint.intValue()); //397189120
并且 BigDecimal
这篇关于c ++或java中的数据类型,用于保存20位整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文