Convert float value to String in Java

static String valueOf(float b) method of String class can be used to convert a float value to String in Java.

For eg. when we pass a float value '23.45f' to valueOf method, it returns a string value '23.45'.


Example 1

class FtoSTest{

public static void main(String args[]){

float f=23.45f;

String floattoSt=String.valueOf(f);

System.out.println(floattoSt);

}

}

Output 1

23.45


Example 2

class FtoSTest{

public static void main(String args[]){

float k=3.45f;

String floattoSt=String.valueOf(k);

System.out.println(floattoSt);

}

}

Output 2

3.45