Conversion From Float to String in Java

You are currently viewing Conversion From Float to String in Java

Conversion from Float to String in Java

//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

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply