Python - Convert float to String


Example 1: Using str() method
my_float=1234.56 #Float

float_to_string=str(my_float)

print(type(my_float))
print(type(float_to_string))

print(float_to_string)
Output:
<class 'float'>
<class 'str'>
1234.56


Example 2: using format() method
my_float=1234.56 #Float

float_to_string=format(my_float,'f')

print(type(my_float))
print(type(float_to_string))

print(float_to_string)
Output:
<class 'float'>
<class 'str'>
1234.560000


Example 3: Using format string
my_float=1234.5678

float_to_string=f"{my_float:.4f}"

print(type(my_float))
print(type(float_to_string))
print(float_to_string)
Output:
<class 'float'>
<class 'str'>
1234.5678



Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.