Convert float to String in Java

Convert float to String in Java Example describes about Convert float to String in Java.

Float class helps to wrap the primitive type value of float in an object.

In addition, Float class provides several useful methods for dealing with float primitives

When we need to Convert float to String in Java, we can use Float.toString(float f) method of Float class, This method will convert the float to String.

If you need a Float object in lieu of primitive float, you can use method Float.valueOf(float f). This method will convert the float primitive to Float Object

Convert float To String In Java

public class ConvertFloatToString {

 
public static void main(String[] args) {

   
float f = 10.2f;
  
   
// convert float to String type
   
System.out.println(Float.toString(f));
  
   
// convert float primitive to Float type
   
System.out.println(Float.valueOf(f));
  
 
}
}
Output
10.2

10.2





Your email address will not be published. Required fields are marked *