How do I remove the limit for integers?

Viewed 141

So, I was doing some testing around to see what the max limit for Integer was, and it is 2147483647. But, I wanted more.

So I switched over to Long, which based on my experiments, the max value for that is 9199999999999999999, which is only just under 9.2 quadrillion I believe.

But, that is still not enough, I want to go to at least 999 Septillion, etc. Is this possible? If not, could I be given a way to convert numbers to letter variable form; (1q, 2S, etc.)? And if I convert them to variable form.

Is there a way to get the actual value of the variable for my config file sake? I will need it for shops and rankups and other stuff.

1 Answers

BigDecimal

You can use BigDecimal. BigDecimal represents an immutable arbitrary-precision signed decimal number. It consists of two parts:

Unscaled value – an arbitrary precision integer Scale – a 32-bit integer representing the number of digits to the right of the decimal point For example, the BigDecimal 3.14 has the unscaled value of 314 and the scale of 2.

We use BigDecimal for high-precision arithmetic. We also use it for calculations requiring control over scale and rounding off behavior. One such example is calculations involving financial transactions.

We can create a BigDecimal object from String, character array, int, long, and BigInteger:

BigDecimal number = new BigDecimal("45");

BigInteger

Or you can use BigInteger.

BigInteger number = new BigInteger("1234567890987654321");

BigInteger represents immutable arbitrary-precision integers. It is similar to the primitive integer types but allows arbitrary large values.

It is used when integers involved are larger than the limit of long type. For example, the factorial of 50 is 30414093201713378043612608166064768844377641568960512000000000000. This value is too big for an int or long data type to handle. It can only be stored in a BigInteger variable.

It is widely used in security and cryptography applications.

Related