展开全部
可以自定义一个round拓展函数来实现这样的功能,下面的代码可供参考,具体可以在此基础上进行调整:create function f_RoundEx
(
@Value float, --需要几舍32313133353236313431303231363533e58685e5aeb931333365666231几入的值
@Digit int, --保留小数位数
@point int --确定是几舍
)
returns float
as
begin
declare @Factor float, @result float,@fPoint float
set @Factor=power(10,@Digit)
set @fPoint = (10-@point-1) * 0.1
if @Value
set @result= floor(@Value*@Factor - @fPoint)/ @Factor
else
set @result = floor(@Value * @Factor + @fPoint)/ @Factor
return @result
end
go--测试实例
select dbo.f_RoundEx(1.244, 2,5)
, dbo.f_RoundEx(1.245, 2,5)
, dbo.f_RoundEx(1.247, 2,5)
select dbo.f_RoundEx(1.245, 2,6)
, dbo.f_RoundEx(1.246, 2,6)
, dbo.f_RoundEx(1.247, 2,6)--测试结果
---------------------- ---------------------- ----------------------
1.24 1.24 1.25
---------------------- ---------------------- ----------------------
1.24 1.24 1.25