Round a Floating Point Number Down to the Nearest Integer?

前端 未结 12 1464
悲哀的现实
悲哀的现实 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:42

    x//1
    

    The // operator returns the floor of the division. Since dividing by 1 doesn't change your number, this is equivalent to floor but no import is needed. Notes:

    1. This returns a float
    2. This rounds towards -∞

提交回复
热议问题