[英]How to remove “Decimal” keyword from the output
我有一个清单:
S_acc=[Decimal('14674.04881484484319092894299'),Decimal('1287243.594400802980099508539')]
我想以这种形式输出:
S_acc=[14674.04881484484319092894299, 1287243.594400802980099508539]
我尝试先转换为字符串,然后再转换为十进制数,但出现此错误:
results = [tuple(str(item) for item in t) for t in s_acc]
print(results)
TypeError: 'decimal.Decimal' object is not iterable
感谢任何帮助。
您接近了,只是:
>>> [str(d) for d in S_acc]
['14674.04881484484319092894299', '1287243.594400802980099508539']
如果要对表示形式有更多控制,请使用格式规范 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.