Python Decimal to String

后端 未结 5 1661
时光取名叫无心
时光取名叫无心 2021-02-03 18:35

There are tons of topics on here that explain how to convert a string to a decimal, but how do I convert a decimal back to a string?

Like if I did this:

         


        
5条回答
  •  有刺的猬
    2021-02-03 18:50

    Use the str() builtin, which:

    Returns a string containing a nicely printable representation of an object.

    E.g:

    >>> import decimal
    >>> dec = decimal.Decimal('10.0')
    >>> str(dec)
    '10.0'
    

提交回复
热议问题