Java.lang Package Classes

Java Float - toString() Method



The java.lang.Float.toString() method returns a new String object representing the specified float argument.

Syntax

public static String toString(float f)

Parameters

f Specify the float to be converted.

Return Value

Returns a string representation of the argument.

Exception

NA.

Example:

In the example below, the java.lang.Float.toString() method returns a String object representing the given float argument.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating a float value
    float x = 25;

    //printing the float value 
    System.out.println("The float value is: " + x); 

    //creating and printing the string 
    //representation of the float value
    String x_tostring = Float.toString(x);
    System.out.println("The string value of float is: " + x_tostring);   
  }
}

The output of the above code will be:

The float value is: 25.0
The string value of float is: 25.0

❮ Java.lang - Float