Write Java program to Convert Float to String


This is a Java program that demonstrates how to convert a float value to a string using the Float.toString() method.

  • In this program, a float variable a is initialized with the value of 88.45f. Then, a null string variable str is declared.
  • The program then uses the System.out.println() method to print the value of the float variable a.
  • Next, the Float.toString() method is called, passing in the float variable a as an argument. This method returns a string representation of the float value. The returned string is then assigned to the str variable.
  • Finally, the program uses the System.out.println() method to print the string representation of the float value that was stored in the str variable.

Source Code

public class FloatToString
{
	public static void main(String args[])
	{
		float a = 88.45f;
		String str = null;
		System.out.println("Float Values : " + a);
 
		//convert float to string
		str = Float.toString(a);
		System.out.println("Float to String : " + str);
	}
}

Output

Float Values : 88.45
Float to String : 88.45