Sitelet https://java2blog.com/python-float-string/

Python float to String

In this tutorial, we will see how to convert float to String.
You can simply use str method to convert float to String.
Let’s understand with the help of simple example.

f=1.23444432
print("Converted f to String:",str(f))

Output:

Converted f to String: 1.23444432

Let’s say you want to format String to only two decimal places.
You can use below code to do it.

f=1.23444432
#Use 5 characters, give 2 decimal places
s = "%5.2f" % f
print("Converted f to String:",s)

Output:

Converted f to String: 1.23

That’s all about converting float to String in python.

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.