drop trailing zeros from decimal

前端 未结 9 1896
庸人自扰
庸人自扰 2020-11-29 03:54

I have a long list of Decimals and that I have to adjust by factors of 10, 100, 1000,..... 1000000 depending on certain conditions. When I multiply them there is sometimes

9条回答
  •  执念已碎
    2020-11-29 04:23

    This should work:

    '{:f}'.format(decimal.Decimal('2.5') * 10).rstrip('0').rstrip('.')
    

提交回复
热议问题