将十进制数转换为 INT SQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36320861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert decimal number to INT SQL
提问by Zaeron25
I want to convert the decimal number 3562.45 to 356245, either as an int
or a varchar
. I am using cast(3562.45 as int)
, but it only returns 3562. How do I do it?
我想将十进制数 3562.45 转换为 356245,作为 anint
或 a varchar
。我正在使用cast(3562.45 as int)
,但它只返回 3562。我该怎么做?
采纳答案by Dan Bracuk
Or you can replace the decimal point.
或者您可以替换小数点。
select cast(replace('3562.45', '.','') as integer)
This way, it doesn't matter how many decimal places you have.
这样,您有多少小数位都无关紧要。
回答by Mike Dinescu
How about the obvious:
显而易见的呢:
CAST(3562.45*100 as INTEGER)
回答by Varun
This works for me
这对我有用
SELECT FLOOR(55.5999)