Round integers to the nearest 10

后端 未结 7 1712
孤街浪徒
孤街浪徒 2020-11-27 17:45

I am trying to round integers in python. I looked at the built-in round() function but it seems that that rounds floats.

My goal is to round integers to the closest

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 18:28

    About the round(..) function returning a float

    That float (double-precision in Python) is always a perfect representation of an integer, as long as it's in the range [-253..253]. (Pedants pay attention: it's not two's complement in doubles, so the range is symmetric about zero.)

    See the discussion here for details.

提交回复
热议问题