To convert a decimal to a string in Python, you can use the Python str() function.

from decimal import Decimal

d = Decimal("1.23")

s = str(d)

print(d, type(d))
print(s, type(s))

#Output:
1.23 
1.23 

When working with different variables in Python, the ability to easily be able to convert a variable into a variable with a different type is valuable.

One such case is if you want to convert a decimal into a string.

The Python decimal module provides support for fast correctly rounded decimal floating point arithmetic.

Sometimes it might make sense to want to convert a decimal into a string.

To convert a decimal to a string in Python, you can use the Python str() function.

Below is an example of how you can convert a decimal into a string using Python.

from decimal import Decimal

d = Decimal("1.23")

s = str(d)

print(d, type(d))
print(s, type(s))

#Output:
1.23 
1.23 

Hopefully this article has been useful for you to learn how to convert a decimal variable into a string using Python.

Categorized in:

Python,

Last Update: March 11, 2024