Convert from float to String in Java

Java 8Object Oriented ProgrammingProgramming

To convert float to string, use the toString() method. It represents a value in a string.

Let’s say the following is our float.

float f = 0.9F;

Converting the float value to string.

String s = Float.toString(f);

Let us see the complete example to convert float to String in Java with output.

Example

 Live Demo

public class Demo {
   public static void main(String args[]) {
      float f = 0.9F;
      String s = Float.toString(f);
      System.out.println(s);
   }
}

Output

0.9
raja
Published on 10-Dec-2018 11:59:39
Advertisements