从CAST DECIMAL到INT [英] CAST DECIMAL to INT

查看:99
本文介绍了从CAST DECIMAL到INT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这样做:

SELECT CAST(columnName AS INT), moreColumns, etc
FROM myTable
WHERE ...

我在这里查看了帮助常见问题解答: http: //dev.mysql.com/doc/refman/5.0/zh-CN/cast-functions.html ,它说我可以像CAST(val AS TYPE)一样进行操作,但是它不起作用.

I've looked at the help FAQs here: http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html , it says I can do it like CAST(val AS TYPE), but it's not working.

尝试将小数转换为int,实际值为223.00,我想要223

Trying to convert a decimal to int, real value is 223.00 and I want 223

推荐答案

您可以尝试

You could try the FLOOR function like this:

SELECT FLOOR(columnName), moreColumns, etc 
FROM myTable 
WHERE ... 

您也可以尝试 FORMAT 函数,前提是您知道小数位可以省略:

You could also try the FORMAT function, provided you know the decimal places can be omitted:

SELECT FORMAT(columnName,0), moreColumns, etc 
FROM myTable 
WHERE ... 

您可以结合使用这两个功能

You could combine the two functions

SELECT FORMAT(FLOOR(columnName),0), moreColumns, etc 
FROM myTable 
WHERE ... 

这篇关于从CAST DECIMAL到INT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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