[英]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.