Java common numerical type value range/int short long BigInteger value range

Article directory

1. Value range of each type

The following summarizes the value ranges of commonly used numerical types in Java.

type Byte size minimum value maximum value Ranges
byte 8bit -128 +127 -128 to 127
short 16bit -2 15 ^{15} 15 +2 15 ^{15} 15-1 -32768-32767
int 32bit -2 31 ^{31} 31 +2 31 ^{31} 31 -1 -2,147,483,648 to 2,147,483,647
float 32 1.4E-45 (2 to the power of -149) 3.4028235E38 (2 to the 128th power -1) The accuracy is 6~7 significant digits
double 64 4.9E-324 (2 to the power of -1074) 1.7976931348623157E308 (2 to the power of 1024-1) The precision is 15~16 digits.
long 64 -2 63 ^{63} 63 +2 63 ^{63} 63 -1 -9223372036854775808~9223372036854775807

Two types are particularly mentioned here:
There are two classes in Java: BigInteger and BigDecimal respectively Represents the 大整数类 and 大浮点数 classes.
Both classes are in the java.math.* package, so the package must be referenced at the beginning every time.

BigInteger Any large integer, 其取值范围在负无穷到正无穷之间, in principle, as long as your computer’s memory is large enough, it can have unlimited digits. When the value exceeds long, it must be processed with BigInteger
BigDecimal Arbitrarily large real numbers can handle decimal precision issues.

Guess you like

Origin blog.csdn.net/weixin_49114503/article/details/134569459