Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store a large (10 digits) integer?

Tags:

java

Which Java data type would be able to store a big numerical value, like 9999999999?

like image 575
silverkid Avatar asked Dec 21 '09 08:12

silverkid


People also ask

Can INT store 10 digits?

The INTEGER data type stores whole numbers that range from -2,147,483,647 to 2,147,483,647 for 9 or 10 digits of precision.

How do you store numbers bigger than long?

You must use BigInteger to store values that exceed the max value of long.

How can I store more than 10 digit numbers in C++?

long long can hold up to 9223372036854775807. Use something like gmp if you need larger. Sure: if the native integer format is 128 bits, a "precisely 64 bits" type requires an &= 0xFFFFFFFFFFFFFFFF operation to be inserted at many points.

Can Int be stored in long?

A maximum integer value that can be stored in a long long int data type is typically 9, 223, 372, 036, 854, 775, 807 around 263 – 1(but is compiler dependent). The maximum value that can be stored in long long int is stored as a constant in <climits> header file.


1 Answers

Your concrete example could be stored in long (or java.lang.Long if this is necessary).

If at any point you need bigger numbers, you can try java.math.BigInteger (if integer), or java.math.BigDecimal (if decimal)

like image 137
Bozho Avatar answered Sep 24 '22 23:09

Bozho