ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.