The variable which is declared using 'float' data type can store decimal values. But the only thing to observe is that the value should end with letter f as shown in the below program.
class Sample
{
public static void main(String args[])
{
float a=123.456f; //Observe that the value to be stored in the float declared variable should end with 'f' letter.
System.out.println(a);
}
}
Output of this program:
123.456
Try this program without adding the letter f at the end of the value. Observe that the program will throw an error on compiling the program.