问题描述
我知道在Java中,一个int可以得到2,147,483,647的值.但是我想要更多的价值.我有一个公式,例如:
I know that in Java an int can get a value of 2,147,483,647. But I want more value than that. I have a formula for example:
double x = a/(b*c);
因此分母(b * c)可以达到10 ^ 10甚至更高.但是无论何时执行公式,该值始终限制为2,147,483,647.我知道,因为x必须始终小于1.0.P/S:如果满足某些条件,即使变量"a"也可以达到10 ^ 10.a,b,c都是整数.
So the denominator (b*c) can reach to 10^10 or maybe even higher than that. But whenever I execute the formula, the value is always limited to 2,147,483,647. I know because x must always be smaller than 1.0.P/S: Even variable "a" can also reach 10^10 if some conditions are satisfied.a,b,c are all integer numbers.
推荐答案
自从您提出要求以来,这是一个BigInteger
示例:
Since you asked for it, here's a BigInteger
example:
BigInteger a = new BigInteger("yourNumberInStringFormA");
BigInteger b = new BigInteger("yourNumberInStringFormB");
BigInteger c = new BigInteger("yourNumberInStringFormC");
BigInteger x = a.divide(b.multiply(c));
其中"yourNumberInStringForm"
是可选的负号和仅数字(没有空格或逗号).例如,BigInteger z = new BigIntger("-3463634");
注意:如果您的电话号码在其范围内,BigInteger
实际上将为您返回一个long
. longs
以L
结尾,如下所示:
Where "yourNumberInStringForm"
is an optional minus sign and numbers only (no whitespace or commas). For example BigInteger z = new BigIntger("-3463634");
NB: BigInteger
will actually return a long
for you if your number is in its range. longs
end in L
, as in:
long num = 372036854775807L;
long
的最大长度为:9,223,372,036,854,775,807.如果您的数字将小于此数字,那么使用long
或Long
作为其包装器,而不是BigInteger
,将使您的生活变得更加轻松.由于使用long
,您不必使用除法/乘法等方法.
The max length for a long
is: 9,223,372,036,854,775,807. If your numbers are going to be less than that, it'll make your life a ton easier to use long
or Long
, its wrapper, over BigInteger
. Since with long
, you don't have to use methods for dividing/multiplying, etc.
这篇关于如何获得大于最大整数值的整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!