将浮点数四舍五入到最接近的整数?
问题描述:
我想要一个浮点数并将其四舍五入为最接近的整数.但是,如果它不是一个整数,那么我总是要舍入该变量,而不管它与下一个整数有多接近.有办法吗?
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 variable, regardless of how close it is to the next integer up. Is there a way to do this?
答
简单
print int(x)
也可以.