How to Convert Float to String in Python

Muhammad Waiz Khan Feb 02, 2024
  1. Python Convert Float to String Using str() Function
  2. Python Convert Float to String Using repr() Function
How to Convert Float to String in Python

This tutorial will explain multiple ways to convert a float to a string in Python. We can convert a float to a string using the str() and repr() functions.

Python Convert Float to String Using str() Function

The str() method takes an object as input and converts it into a string type. The example code below demonstrates how to use the str() function to convert a float to string in Python.

my_float = 0.125

string = str(my_float)
print(string)
print(type(string))

Output:

0.125
<class 'str'>

Python Convert Float to String Using repr() Function

The repr() method converts an object into a printable string. The example code below demonstrates how the repr() function converts a float to a string in Python.

my_float = 0.125

string = repr(my_float)
print(string)
print(type(string))

Output:

0.125
<class 'str'>

Related Article - Python Float

Related Article - Python String