Tutorialspoint examples

Learn java tutorial with examples for beginners online

Convert float to string java program


Java convert float to string using Float.toString() method

package com.tutorialspointexamples;
 
public class FloatToString {
  public static void main(String args[]){
	try {
		float var = -5.24f;
                String str = Float.toString(var);
                System.out.println("String is: "+str);
	} catch (Exception e) {
		e.printStackTrace();
	}
  }
}

Output:

String is: -5.24

Download this example.

Java convert float to string using String.valueOf() method

package com.tutorialspointexamples;
 
public class FloatToString {
  public static void main(String args[]){
	try {
		float var = 5.24f;
                String str = String.valueOf(var);
                System.out.println("String is: "+str);
	} catch (Exception e) {
		e.printStackTrace();
	}
  }
}

Output:

String is: 5.24

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status