Skip to content

Convert Float to string Python | Example code

  • by

Use str() to convert float to a string in Python. It’s a built-in function. Here’s how you can do it:

float_number = 3.14159
string_representation = str(float_number)
print(string_representation)

In this example, the str() function is used to convert the float_number variable to its string representation, which is then stored in the string_representation variable. Finally, the print() function is used to display the converted string.

Example how to convert float to String in Python

A simple example code converts a floating object to a string in Python. Let’s convert the float 1.99 to a string returns "1.99".

After converting check the type and print it into the console.

f = 1.99

res = str(f)

print(res)
print(type(res))

Output:

Convert Float to string Python

Comment if you have any doubts or suggestions on this Python float string topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *