Home » Java Convert float to String

Java Convert float to String

by Online Tutorials Library

Java Convert float to String

We can convert float to String in java using String.valueOf() and Float.toString() methods.

Java Convert float to String

Scenario

It is generally used if we have to display float value in textfield because everything is displayed as a string in form.


1) String.valueOf()

The String.valueOf() is an overloaded method. It can be used to convert float to String. The valueOf() is the static method of String class. The signature of valueOf() method for the float conversion is given below:

Java float to String Example: String.valueOf()

Let’s see the simple code to convert float to String in java.

Example:

Test it Now

Output:

12.3 

2) Float.toString()

The Float.toString() method also converts float to String. The toString() is the static method of Float class. The signature of toString() method is given below:

Java float to String Example: Float.toString()

Let's see the simple code to convert float to String in java using Float.toString() method.

Example:

Test it Now

Output:

89.7 

You may also like