How to Convert Float to String in Python
Muhammad Waiz Khan
Feb 02, 2024
-
Python Convert Float to String Using
str()
Function -
Python Convert Float to String Using
repr()
Function
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
- How to Find Maximum Float Value in Python
- How to Fix Float Object Is Not Callable in Python
- How to Convert a String to a Float Value in Python
- How to Check if a String Is a Number in Python
- How to Convert String to Decimal in Python
- How to Convert List to Float in Python