Q:

Conversion from Float to String in Java

belongs to collection: Java Conversion Programs

0

Given a float value and we have convert it into string.

Java conversion from Float to String

To convert a Float to String, we use toString() method of Float class, it accepts a float value and returns the string value.

Syntax:

    Float.toString(float);

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Java code to convert a Float to String

//Java code to convert afloat to String
public class Main {
    public static void main(String args[]) {
        float a = 10.23f;
        float b = 23.456f;

        //variable to store result
        String result = null;

        //converting float to string
        result = Float.toString(a);
        System.out.println("result (value of a as string) = " + result);

        result = Float.toString(b);
        System.out.println("result (value of b as string) = " + result);
    }
}

Output

result (value of a as string) = 10.23
result (value of b as string) = 23.456

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Conversion from String to Integer in Java... >>
<< Conversion from Long to String in Java...