Python Convert Float to String

Convert Float to String

To convert given floating-point number to a string in Python, call str() builtin function and pass the floating-point number as argument to the str() function. str() returns the string formed using the given value.

The syntax to convert a floating-point number a into string is as shown in the following.

myString = str(a)

In this tutorial, we shall go through some of the examples using str() builtin function to convert a floating-point number into a string.

Example

In the following program, we will take a floating-point number in variable a, convert it to string using str().

Python Program

# Take a float value
a = 3.14
print('Input', a, type(a), sep='\n')

# Convert float to string
output = str(a)
print('\nOutput', output, type(output), sep='\n')
Run Code Copy

Output

Input
3.14
<class 'float'>

Output
3.14
<class 'str'>

Summary

In this tutorial of Python Examples, we learned to convert a value of float datatype to a value of string datatype using str() function.

Related Tutorials

Code copied to clipboard successfully 👍