避免显式强制浮动?

时间:2020-02-21 09:36:11

标签: sql sql-server casting default

可以

SELECT CAST(2.083 AS float) AS c

以更紧凑的方式编写吗?

类似

SELECT 2.083f AS c

1 个答案:

答案 0 :(得分:3)

要避免将CAST显露到float,请指定floating point constant expression

--these both return float with precision 53
EXEC sp_describe_first_result_set N'SELECT CAST(2.083 AS float) AS c;';
EXEC sp_describe_first_result_set N'SELECT 2.083E0 AS c;';

--without scientific notation, the constant is interpreted as numeric(4,3)
EXEC sp_describe_first_result_set N'SELECT 2.083 AS c;';