Java convert float to string using Float.toString() method
package com.w3spoint;
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();
}
}
} |
package com.w3spoint; 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:
Download this example.
Java convert float to string using String.valueOf() method
package com.w3spoint;
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();
}
}
} |
package com.w3spoint; 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:
Download this example.