java.lang.String valueOf(float f)

Description :

This java tutorial shows how to use the valueOf(float f) method of String class of java.lang package. This method returns a string representation of float data type. This will yield the same result as Float.toString(float).

Method Syntax :

public static String valueOf(float f)

Parameter Input :

DataType Parameter Description
float f method parameter which we are interested to get the string equivalent

Method Returns :

The String valueOf() method with argument float returns a new String object which corresponds to the string representation of the method argument.

Compatibility Version :

Since the beginning

Exception :


Discussion :

The string valueOf(float f) method is simply to get a String equivalent of float method parameter. This method be statically accessed which means we should call the method like String.valueOf(float f).

Java Code Example :

This example source code demonstrates the use of valueOf(float f) of String class. Below are different examples of getting a value of float. As you would noticed we have used the unboxing functionality to transform a Float object into float primitive datatype and then get the string equivalent using the valueOf method.


 * Java example source code to get the value of primitive float data type

public class StringValueOfFloat {

	public static void main(String[] args) {

		// primitive float declaration
		float val = 1.0f;
		// Object of Float data type
		Float valueFloat = 100.125f;


Sample Output :

Running the valueOf() method example source code of String class will give you the following output

java string indexOf(float) method example

java string indexOf(float) method example

Exception Scenario :


Suggested Reading List :

References :