Main Tutorials

Python – How to convert float to String

In Python, we can use str() to convert float to String.


pi = 3.1415

print(type(pi))  # float

piInString = str(pi)  # float -> str

print(type(piInString))  # str

Output


<class 'float'>
<class 'str'>

References

  1. Python docs – str()
  2. Python – How to convert int to String
  3. Python – How to convert String to float

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Matthew
4 years ago

No, it’s not working

Eric
4 years ago
Reply to  Matthew

Have you checked out python convert int to string

eric

Code_py.salut
2 years ago

c’est une mauvaise technique de faire nombre = str(nombre)

car si on fait 5219174198521.17495127414 = str(5219174198521.17495127414)
on obtient 5219174198521.175
alors que l'on veut '5219174198521.17495127414'
c'est pour ça que c'est trés problèmatique avec les flottants (float)
satish
2 years ago

# variable expr1 and its value
expr1 = 1700/19
print(“The value of expr1:”, expr1)

# variable expr2
expr2 = _1700/19_
print(“The value of converted into string expr2:”, _ _ _)