-1

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 .

  • 1
    double and long can represent a greater range, and for double higher precision as well. An int can hold numbers in the range -2147483648 to 2147483647 while a long has a greater range (-9223372036854775808 to 9223372036854775807). Likewise, double has a greater range and higher precision(4.94065645841246544e-324 to 1.79769313486231570e+308) compared to float(1.40239846e-45f to 3.40282347e+38f) – NGY Nov 05 '22 at 06:50
  • Never use float or double for representing decimal numbers (or you have really understood IEEE Floating-Point Arithmetic). First, prefer [BigDecimal](https://www.baeldung.com/java-bigdecimal-biginteger). – PeterMmm Nov 05 '22 at 09:58

1 Answers1

0

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.

Christoph Dahlen
  • 826
  • 3
  • 15