将浮点数四舍五入到最接近的整数? [英] Round a floating-point number down to the nearest integer?

查看:59
本文介绍了将浮点数四舍五入到最接近的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个浮点数并将其四舍五入为最接近的整数.但是,如果它不是一个整数,那么我总是要舍入该变量,而不管它与下一个整数有多接近.有办法吗?

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)

也可以.

这篇关于将浮点数四舍五入到最接近的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆