float

The $\lstinline{float}$ data type is a single-precision 32-bit floating-point. Learn more about single-precision and double-precision floating-point if you are interested. It should never be used for precise values such as currency. Default value is 0.0 (0.0f).


\begin{lstlisting}
class FloatExample {
public static void main(String[] args) ...
...r
float number = -42.3f;
System.out.println(number);
}
}
\par
\end{lstlisting}

Notice that, we have used $-42.3f$ instead of $-42.3$ in the above program. It's because $-42.3$ is a double literal. To tell the compiler to treat $-42.3$ as $\lstinline{float}$ rather than $\lstinline{double}$, you need to use f or F.