Here we are going to see how we can convert a string value to float.
String to Float Conversion
String to float conversion in java is too easy. We can directly convert a String to float by using Float.parseFloat(String s) .
String s = "26.7";
float f = Float.parseFloat(s);
Let’s see a complete java program to convert string to float.
StringToFloat.java
package gangforcode;
public class StringToFloat {
public static void main(String[] args) {
String s = "26.7";
float f = Float.parseFloat(s);
}
}
Float to String conversion
Similarly we can convert a float value into string by using Float.toString(float f). for more info you can check here https://gangforcode.com/float-to-string-conversion-in-java/
Similar Java Tutorial
Hello World – https://gangforcode.com/java-code-to-print-hello-world/
data types in java – https://gangforcode.com/data-types-in-java/
identifiers in java – https://gangforcode.com/identifiers-in-java/
keywords in java – https://gangforcode.com/keywords-in-java/
Multidimensional Array in Java – https://gangforcode.com/multidimensional-array-in-java/
Matrix Addition in Java – https://gangforcode.com/matrix-addition-in-java/
Binary Search in Java – https://gangforcode.com/binary-search-in-java/