将浮点数舍入到最近的整数? [英] Round a Floating Point Number Down to the Nearest Integer?

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

问题描述

正如标题所暗示的,我想获取一个浮点数并将其舍入到最接近的整数。但是,如果它不是一个整体,我总是想要舍入变量,不管它与下一个整数有多接近。有没有办法做到这一点?

解决方案

简单的

  print int(x)

也可以。 >

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 variable, regardless of how close it is to the next integer up. Is there a way to do this?

解决方案

Simple

print int(x)

will work as well.

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

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