Convert Int to Float in Java

  1. Use the floatValue() Function to Convert an Integer Into a Float in Java
  2. Use the Typecasting Method to Convert an Integer Into a Float in Java

Float values represent decimal point numbers in Java. It is one of the fundamental data types used in almost all programming languages.

This tutorial will demonstrate how to convert integer to float in Java.

Use the floatValue() Function to Convert an Integer Into a Float in Java

The floatValue() function can convert a given integer value into float. It belongs to the java.lang.Integer class.

For example,

import java.lang.Integer;

public class Main {
    public static void main(String args[])
    {
        Integer a = new Integer(56);

        float b = a.floatValue();

        System.out.println(b);
    }
}

Output:

56.0

Use the Typecasting Method to Convert an Integer Into a Float in Java

Typecasting is a method in which you convert one type of data type into some other type explicitly. By using this technique, we can convert an integer value into a float value.

To typecast an integer value to float, we will use the float keyword.

See the code given below.

public class Main {
    public static void main(String args[])  
    {  
        int i = 56;  
        float f = i;  
        System.out.println(f);       
    }  
} 

Output:

56.0
Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Java Float

  • Float and Double Data Type in Java
  • Related Article - Java Integer

  • Check if Input Is Integer in Java
  • Convert Boolean to Int in Java