任何人都可以告诉我,
如何在SQL Server 2008 R2中将7.3050
更改为7.3000
?
我试过了:
Select ROUND(7.3050,2)
结果:7.31
但我需要结果:7.30
答案 0 :(得分:3)
您可以这样使用FLOOR
功能:
FLOOR(7.30502 * 100) / 100
如果可以更改零的数量,将其四舍五入到所需的位数。
答案 1 :(得分:0)
你得到的取决于你如何开始。数据类型很重要。
create table test (
n decimal(10, 4) not null,
r float not null
);
insert into test values (7.3050, 7.3050);
select round(n, 2) as n_rounded,
round(r, 2) as r_rounded
from test;
N_ROUNDED R_ROUNDED
--
7.31 7.3
round 的含义也很重要。当你谈到“舍入”7.3050到7.30(假设一个十进制数据类型)时,你可能真的不是在谈论舍入。 (我们无法确定。)它可以你想要截断到一个小数位 - 你要映射7.300到7.309之间的所有值以映射到7.3。
insert into test values (7.3000, 7.3000);
insert into test values (7.3090, 7.3090);
select round(n, 2, 1) as n_trunc,
round(r, 2, 1) as r_trunc
from test;
N_TRUNC R_TRUNC
--
7.3 7.3
7.3 7.29
7.3 7.3
请注意float列的行为。
答案 2 :(得分:0)
您可以使用此查询:
Select ROUND(7.3050,1)
结果是7.3000