Limiting floats to two decimal points

前端 未结 28 3151
你的背包
你的背包 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:15

    The built-in round() works just fine in Python 2.7 or later.

    Example:

    >>> round(14.22222223, 2)
    14.22
    

    Check out the documentation.

提交回复
热议问题