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

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Matthew
6 years ago

No, it’s not working

Eric
6 years ago
Reply to  Matthew

Have you checked out python convert int to string

eric

Code_py.salut
4 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
4 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:”, _ _ _)