简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM