Java.lang Package Classes

Java Float - toString() Method



The java.lang.Float.toString() method returns a string representation of this Float object. The primitive float value represented by this object is converted to a String exactly as if by the method toString of one argument.

Syntax

public String toString()

Parameters

No parameter is required.

Return Value

Returns a String representation of this object.

Exception

NA.

Example:

In the example below, the java.lang.Float.toString() method returns a String object representing the given Float's value.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Float object
    Float x = 25.2f;

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

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

The output of the above code will be:

The Float object is: 25.2
The string value of Float is: 25.2

❮ Java.lang - Float