How to Convert float to String in Java

This post shows how you can convert float to String in Java.

Converting float to String using Float.toString() method

Wrapper class Float in Java has a toString() method that returns a string representation of the passed float argument.

Output

Convert using String.valueOf() method

String.valueOf(float f)– Returns the string representation of the float argument.

Output

Converting using String concatenation

You can concatenate the float value with an empty string (“”) that will return the result as a String. That’s one way to convert float to String

Output

Converting using append method of StringBuilder or StringBuffer class

Both StringBuilder and StringBuffer classes have append() method where you can pass float as an argument. The append() method will append the string representation of the float argument to the sequence.

Output

That’s all for the topic How to Convert float to String in Java. If something is missing or you have something to share about the topic please write a comment.


You may also like

  • How to Convert String to double in Java
  • How to Create PDF From XML in Java Using Apache FOP
  • ListIterator in Java
  • Volatile Keyword in Java
  • Marker Interface in Java
  • How to Improve Map-Reduce Performance
  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.