[英]How to remove “Decimal” keyword from the output
I have a list: 我有一个清单:
S_acc=[Decimal('14674.04881484484319092894299'),Decimal('1287243.594400802980099508539')]
I would like to have output in this form: 我想以这种形式输出:
S_acc=[14674.04881484484319092894299, 1287243.594400802980099508539]
I tried converting into string first before converting to decimal number but I am getting this error: 我尝试先转换为字符串,然后再转换为十进制数,但出现此错误:
results = [tuple(str(item) for item in t) for t in s_acc]
print(results)
TypeError: 'decimal.Decimal' object is not iterable
Appreciate any help. 感谢任何帮助。
You were close, it's just: 您接近了,只是:
>>> [str(d) for d in S_acc]
['14674.04881484484319092894299', '1287243.594400802980099508539']
Use format specs if you want more control over the representation. 如果要对表示形式有更多控制,请使用格式规范 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.