To round a float number to an integer in Python, you can use the built-in round() function together with the int() function. Here's an example:

x = 3.14159
y = int(round(x))
print(y)  # Output: 3

In this example, we first define a float number x with value 3.14159. We then use the round() function to round the number to the nearest integer, which gives us 3.0. Finally, we use the int() function to convert the float to an integer, which gives us the final result of 3.

python round to int

原文地址: http://www.cveoy.top/t/topic/btL3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录