如何从outpu中删除“Decimal”关键字

2024-04-26 21:36:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个清单:

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

谢谢你的帮助。你知道吗


Tags: 字符串inforobject错误itemresults形式