[英]How to truncate then round a number in SQL Server 2008 R2
Given these 2 examples, what is the correct syntax to round each example to the whole number.给定这两个示例,将每个示例四舍五入为整数的正确语法是什么。 This must be a set operation as the decimal is from a column.
这必须是集合操作,因为小数来自列。
96.001 will be 96 96.001 将是 96
80.01 will be 81 80.01 将是 81
Thank you, Stephen谢谢你,斯蒂芬
;WITH T(C) AS
(
SELECT 96.001
UNION ALL
SELECT 80.01
)
SELECT CEILING(CAST(C AS DECIMAL(18,2)))
FROM T
You are looking for the CEILING
and FLOOR
functions.您正在寻找
CEILING
和FLOOR
功能。
declare @myVar1 decimal(6,2)
declare @myVar2 decimal(6,2)
set @myvar1 = 96.001
set @myvar2 = 80.01
SELECT @myvar1, CAST(CEILING(@myVar1) as int), @myvar2, CEILING(@myVar2)
Result:结果:
96.001 | 96 | 80.010 | 81
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.