将十进制数转换为 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:31:14  来源:igfitidea点击:

Convert decimal number to INT SQL

sqlsql-servercastingdecimalnumber-formatting

提问by Zaeron25

I want to convert the decimal number 3562.45 to 356245, either as an intor 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)

回答by arman1991

You can use also the CONVERTfunction:

您还可以使用CONVERT函数:

SELECT CONVERT(INT, 3562.45 * 100)