Round a Floating Point Number Down to the Nearest Integer?

前端 未结 12 1462
悲哀的现实
悲哀的现实 2020-12-02 13:45

As the title suggests, I want to take a floating point number and round it down to the nearest integer. However, if it\'s not a whole, I ALWAYS want to round down the variab

12条回答
  •  猫巷女王i
    2020-12-02 14:34

    One of these should work:

    import math
    math.trunc(1.5)
    > 1
    math.trunc(-1.5)
    > -1
    math.floor(1.5)
    > 1
    math.floor(-1.5)
    > -2
    

提交回复
热议问题