CodesJava

Easy learning with example program codes

Float to string in java

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

package com.codesjava;
 
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.codesjava;
 
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.

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status