Limiting floats to two decimal points

前端 未结 28 3205
你的背包
你的背包 2020-11-21 04:57

I want a to be rounded to 13.95.

>>> a
13.949999999999999
>>> round(a, 2)
13.949999999999999

The ro

28条回答
  •  伪装坚强ぢ
    2020-11-21 05:29

    Use

    print"{:.2f}".format(a)
    

    instead of

    print"{0:.2f}".format(a)
    

    Because the latter may lead to output errors when trying to output multiple variables (see comments).

提交回复
热议问题