python - 你可以在python中将一个浮点数的字符串转换为一个整数吗?(在 1 个步骤中)
问题描述
例子:
string = "12.4"
x = int(string)
只是好奇是否有办法直接做到这一点,或者如果你只需要转换为 float 然后转换为 int 作为 2 个步骤。
解决方案
x="12.4"
x=int(float(x))# this float(x) first converts the string x into float and
#then int() function converts now newly float x int int x
推荐阅读
- python - 如何在“顶级”Tkinter 窗口内缩放标签字体大小?
- google-apps-script - 我如何识别单元格中的单词以触发操作
- c - 如何将可执行文件名称插入到 perror 错误消息中?
- cors - 当响应“204 no content”到一个简单的请求时,我可以从响应头中省略 Access-Control-Allow-Origin 吗?
- html - 如何使用导航订购列表?
- python - 如何在我的 DataFrame 中添加一列,显示哪些企业有社交媒体,哪些企业没有?
- kubernetes - kubernetes:如何查看或列出已安装的 CNI 插件?
- node.js - 等待高地溪流的完成
- google-apps-script - 如何绕过 Google App Script 中附加组件的时间触发限制?
- javascript - 正则表达式与两个 / 匹配精确路径