Possible Duplicate:
drop trailing zeros from decimal
如何得到比较相等的Decimal
的最短表示?你知道吗
例如:
Decimal('89.00')
->;'89'
Decimal('123.010')
->;'123.01'
Decimal('0.0')
->;'0'
目前,我有自己的实现,它首先转换为字符串
if chanstr.endswith('0'):
chanstr = chanstr[:chanstr.rfind('.')]
哪一个写得很好,而且只有2个LOC;但是有没有更好的方法来写这个呢?你知道吗
您可以使用normalize方法来实现这一点:
另见this answer。你知道吗
相关问题 更多 >
编程相关推荐