The minimum and maximum values of the Java primitive types (numbers only) are as below. This will help you to declare the appropriate numeric type for your variable.
byte -128 to 127
short -32768 to 32767
int -2147483648 to 2147483647
long -9223372036854775808 to 9223372036854775807
float 1.4E-45 to 3.4028235E38
double 4.9E-324 to 1.7976931348623157E308
You can get the result from the following Java code:
System.out.println("byte "+Byte.MIN_VALUE+" to "+Byte.MAX_VALUE);
System.out.println("short "+Short.MIN_VALUE+" to "+Short.MAX_VALUE);
System.out.println("int "+Integer.MIN_VALUE+" to "+Integer.MAX_VALUE);
System.out.println("long "+Long.MIN_VALUE+" to "+Long.MAX_VALUE);
System.out.println("float "+Float.MIN_VALUE+" to "+Float.MAX_VALUE);
System.out.println("double "+Double.MIN_VALUE+" to "+Double.MAX_VALUE);
The minimum & maximum value of float & double in plain string are given in the table below:
byte -128 to 127
short -32768 to 32767
int -2147483648 to 2147483647
long -9223372036854775808 to 9223372036854775807
float 1.4E-45 to 3.4028235E38
double 4.9E-324 to 1.7976931348623157E308
You can get the result from the following Java code:
System.out.println("byte "+Byte.MIN_VALUE+" to "+Byte.MAX_VALUE);
System.out.println("short "+Short.MIN_VALUE+" to "+Short.MAX_VALUE);
System.out.println("int "+Integer.MIN_VALUE+" to "+Integer.MAX_VALUE);
System.out.println("long "+Long.MIN_VALUE+" to "+Long.MAX_VALUE);
System.out.println("float "+Float.MIN_VALUE+" to "+Float.MAX_VALUE);
System.out.println("double "+Double.MIN_VALUE+" to "+Double.MAX_VALUE);
Here for float, 1.4E-45 means 1.4 x 10-45
flaot minimum value | 0.000000000000000000000000000000000000000000001401298464324817070923729583 28991613128026194187651577175706828388979108268586060148663818836212158203 125 |
float maximum value | 340282346638528859811704183484516925440 |
double minimum value | 0.000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000494065645841246544176568792868221372365059802 61432476442558568250067550727020875186529983636163599237979656469544571773 09266567103559397963987747960107818781263007131903114045278458171678489821 03688718636056998730723050006387409153564984387312473397273169615140031715 38539807412623856559117102665855668676818703956031062493194527159149245532 93054565444011274801297099995419319894090804165633245247571478690147267801 59355238611550134803526493472019379026810710749170333222684475333572083243 19360923828934583680601060115061698097530783422773183292479049825247307763 75927247874656084778203734469699533647017972677717585125660551199131504891 10145103786273816725095583738973359899366480994116420570263709027924276754 4565229087538682506419718265533447265625 |
double maximum value | 17976931348623157081452742373170435679807056752584499659891747680315726078 00285387605895586327668781715404589535143824642343213268894641827684675467 03537516986049910576551282076245490090389328944075868508455133942304583236 90322294816580855933212334827479782620414472316873817718091929988125040402 6184124858368 |