September 14, 2009 at 5:02 am
Please execute the below two sqls stmts and you will find some discrepancy in the result
select round ('6.465',2) --- result 6.46
select round (6.465,2) --- result 6.47
select round ('6.466',2) --- result 6.47
select round (6.466,2) --- result 6.47
Could somebody explain me why this discrepancy is?
Thanks in advance.
September 14, 2009 at 6:38 am
It's because you're relying on an implicit conversion from a string to a decimal data type which SQL server will do to 2 decimal places by default, so you're losing precision before the Round.
Try this:
select round (cast('6.465' as decimal(10,3)),2)
select round (6.465,2)
select round (cast('6.466'as decimal(10,3)),2)
select round (6.466,2)
September 14, 2009 at 6:48 am
Thanks for the reply.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply