Conversion from Float to String in Java

Java conversion from Float to String: Here, we are going to learn how to convert a given float value to string in Java?
Submitted by IncludeHelp, on July 15, 2019

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);

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

Java Conversion Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.