Python defines type conversion functions to directly convert one data type to another. This article is aimed at providing the information about converting decimal to string.
Converting Decimal to String
str() method can be used to convert decimal to string in Python.
Syntax: str(object, encoding=’utf-8?, errors=’strict’)
Parameters:
object: The object whose string representation is to be returned.
encoding: Encoding of the given object.
errors: Response when decoding fails.
Example 1:
Python3
from decimal import Decimal dec = Decimal(10)print(dec, type(dec)) # Converting to stringdec = str(dec)print(dec, type(dec)) |
Output:
10 <class 'decimal.Decimal'> 10 <class 'str'>
Example 2:
Python3
from decimal import Decimal dec = Decimal("0.01")print(dec, type(dec)) # Converting decimal to strings = str(dec)print(s, type(dec)) |
Output:
0.01 <class 'decimal.Decimal'> 0.01 <class 'decimal.Decimal'>

… [Trackback]
[…] Read More Info here on that Topic: geeksforgeeks.org/convert-decimal-to-string-in-python/ […]
… [Trackback]
[…] There you can find 2617 more Information on that Topic: geeksforgeeks.org/convert-decimal-to-string-in-python/ […]
… [Trackback]
[…] Find More to that Topic: geeksforgeeks.org/convert-decimal-to-string-in-python/ […]
… [Trackback]
[…] Read More here on that Topic: geeksforgeeks.org/convert-decimal-to-string-in-python/ […]