这里有很多主题解释了如何将字符串转换为小数,但是如何将小数转换回字符串?
如果我这样做了:
import decimal
dec = decimal.Decimal('10.0')
如何取出 dec
并取出 '10.0'
(字符串)?
最佳答案
使用 the str()
builtin ,其中:
Returns a string containing a nicely printable representation of an object.
例如:
>>> import decimal
>>> dec = decimal.Decimal('10.0')
>>> str(dec)
'10.0'
关于Python十进制到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11093021/