文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>sql server round函数的疑惑

sql server round函数的疑惑

时间:2011-04-23  来源:Gavin.Yao

今天在为项目解决一个问题的时候,碰到一个很操蛋的问题。

关于ROUND函数,我们平常理解为4舍5入,如:

print ROUND(12.555, 2);

结果为:12.56

 

另外看三段脚本:

1,

declare @Value1 float, @Digit1 int
set @Value1=12.055;
set @Digit1=2;
print '12.055 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.155;
print '12.155 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.255;
print '12.255 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.355;
print '12.355 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.455;
print '12.455 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.555;
print '12.555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.655;
print '12.655 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.755;
print '12.755 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.855;
print '12.855 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.955;
print '12.955 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);

12.055 --> 12.05
12.155 --> 12.15
12.255 --> 12.26
12.355 --> 12.36
12.455 --> 12.46
12.555 --> 12.55
12.655 --> 12.65
12.755 --> 12.76
12.855 --> 12.86
12.955 --> 12.96

 

2,

declare @Value1 float, @Digit1 int
set @Value1=12.0555;
set @Digit1=2;
print '12.0555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.1555;
print '12.1555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.2555;
print '12.2555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.3555;
print '12.3555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.4555;
print '12.4555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.5555;
print '12.5555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.6555;
print '12.6555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.7555;
print '12.7555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.8555;
print '12.8555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.9555;
print '12.9555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);

12.0555 --> 12.06
12.1555 --> 12.16
12.2555 --> 12.26
12.3555 --> 12.36
12.4555 --> 12.46
12.5555 --> 12.56
12.6555 --> 12.66
12.7555 --> 12.76
12.8555 --> 12.86
12.9555 --> 12.96

 

3,

declare @Value1 float, @Digit1 int
set @Value1=12.0555;
set @Digit1=3;
print '12.0555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.1555;
print '12.1555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.2555;
print '12.2555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.3555;
print '12.3555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.4555;
print '12.4555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.5555;
print '12.5555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.6555;
print '12.6555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.7555;
print '12.7555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.8555;
print '12.8555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);
set @Value1=12.9555;
print '12.9555 --> ' + cast(ROUND(@Value1, @Digit1) as varchar);

12.0555 --> 12.056
12.1555 --> 12.155
12.2555 --> 12.255
12.3555 --> 12.355
12.4555 --> 12.456
12.5555 --> 12.556
12.6555 --> 12.656
12.7555 --> 12.755
12.8555 --> 12.855
12.9555 --> 12.956

 阿斯多夫

 

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载