0

Java primitive float and double

Any floating-point literal in Java is by default of a double type. Consider the following codes with compilation error from the Eclipse IDE

8-8-2016 10-37-30 AM

Floating-point literal 13.1 is of type double by default

To fix this problem, place “f” or “F” at the end of the literal.

8-8-2016 10-44-22 AM

We can assign integral literals to variables of either float or double type without any special suffixes.

8-8-2016 10-47-48 AM

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert