OneBite.Dev - Coding blog in a bite size

convert variable from float to string in java

Code snippet on how to convert variable from float to string in java

    float number = 3.14f;
    String stringNumber = Float.toString(number);

This code stores a float (a number with decimals, like 3.14) in the variable “number” and then converts it to a string (a series of characters, like “3.14”) and stores it in the “stringNumber” variable. The first line simply declares a float variable called “number” and sets its value to 3.14f. The “f” indicates that the value is a float. The second line uses the Float.toString() class to convert the float variable “number” to a string variable “stringNumber”.

java