开发者

SSRS 2005 Round(foo, 0) is rounding a decimal value of 12.6 to 12 instead of 13

开发者 https://www.devze.com 2023-02-16 05:28 出处:网络
I have a report field that can contain different types of data, therefore I need to do my rounding and formatting using functions.

I have a report field that can contain different types of data, therefore I need to do my rounding and formatting using functions.

In one case, I have a decimal(9,2) value storing hours开发者_运维技巧 that I need to display as minutes with zero decimal places.

Round(foo*60, 0), where foo = .01 (which is 0.6 when multiplied by 60), is outputting 1 like I would expect.

Round(foo*60, 0), where foo = .21 (which is 12.6 when multiplied by 60), is outputting 12 instead of 13.

Why? How can I get it to consistently use standard 4/5 rounding?


Take a look at this other stackoverflow question:

SQL Server Reporting Services Round() function

You are seeing Round to Even logic rather than mid point rounding.

This Wikipedia article has all the details about rounding: Wikipedia Rounding Article


I can't reproduce your results. Perhaps you are hiding some other relevant details.

Declare @foo Decimal(9,2)
Set @foo = 0.21

Select Round(@Foo * 60, 0), @foo * 60

The output from the above code is 13.00 and 12.60 respectively.

Is it possible that the Foo column is a float, or that there is more precision in the foo column that you expect? For example, the following code produces 12 (instead of 13).

Declare @foo float
Set @foo = 0.208

Select Round(@Foo * 60, 0), @foo * 60, Round(@foo, 2)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号