How to convert a float to a String in Python

Python converts Floats to Strings using the str method.

Syntax:

str(self.number)

When checking type compatibility Python can generate an error like the following if the type is not correct:

TypeError at /admin/portfolio/portfolio/

must be str, not float

Adding a call to str() around the value will convert the float value to a String one.


References:

Python