Python Convert Float to String

Python Convert Float to String

  1. Python Convert Float to String Using str() Function
  2. 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

  • Find Maximum Float Value in Python
  • Fix Float Object Is Not Callable in Python
  • Convert a String to a Float Value in Python
  • Check if a String Is a Number in Python
  • Convert String to Decimal in Python
  • Convert List to Float in Python
  • Related Article - Python String

  • Remove Commas From String in Python
  • Check a String Is Empty in a Pythonic Way
  • Convert a String to Variable Name in Python
  • Remove Whitespace From a String in Python
  • Extract Numbers From a String in Python
  • Convert String to Datetime in Python