Java primitive float and double

Last Updated on

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

Professional Software Developer