Home > Mobile >  What is double and long values in java , What make it different from int and float value?
What is double and long values in java , What make it different from int and float value?

Time:11-05

What is double and float values in Java and What makes it different from int and float type ?

basically I want to know about the double and long type in Java how does they work and and when to use them instead of int and float .

CodePudding user response:

int is 4 bytes, long is 8 bytes. The range of possible numbers is bigger from long to int.

Same goes for double and float, but with decimals.

See MIN_VALUE and MAX_VALUE field on the wrapper classes java.lang.Integer, java.lang.Long, java.lang.Float and java.lang.Double.

CodePudding user response:

Java has various data types. Data types are divided into primitive and reference. Primitive data types can be whole-number, decimal, char, etc. double and float are decimal data types. So they store decimal numbers.
The difference between double and float is that float is slightly more precise, it has a precision of 7 numbers. double is more accurate because it has a precision of 15 - 16 numbers.

Whole-number data types include byte, short, int and long. a byte is the smallest, ranging from -128 to 127, but takes up only 8 bits. It is therefore appropriate to use it, for example, to store age. short has a range of -32,768 to 32,767 and is 16 bits long. int is the most used, has a range of -2,147,483,648 to 2,147,483,647, and occupies 32 bits. A long has the range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and occupies 64 bits.

  •  Tags:  
  • java
  • Related