|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, August 20, 2012 10:20 AM
Points: 197,
Visits: 98
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 12:39 PM
Points: 1,662,
Visits: 1,708
|
|
This is an excellent question, kinda reminded me of good ol' days when I worked with Access , thank you Timothy. The difference between Access and SQL Server is caused by the difference in so called mid point rounding rule:
Access uses to even rule SQL Server uses away from zero rule.
Oleg
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:42 PM
Points: 877,
Visits: 1,158
|
|
Though I got it right, its nice to see difference between Access & SQL server in rounding the number. Thanks for the question, I remembered my old days when we worked in Access :)
Thanks
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:24 AM
Points: 5,232,
Visits: 7,022
|
|
Thanks for a good question!
Here in the Netherlands, only one type of rounding is taught in school. The type that Wikipedia calls "away from zero" - you only check the first digit to be discarded, for 0-4 (truncate), or 5-9 (add one to previous digit). I was aware of "bankers rounding" (or "round to even") through questions in forums and usenet. But until I followed the Wikipedia link in the documentation, I did not klnow that there are so many other ways of rounding.
Thanks!
(BTW, did you also file a documentation bug because the SQL Server documentation doesn't specify its tie-breaking rule?)
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 7:36 AM
Points: 2,716,
Visits: 981
|
|
My opinion is that none of the answers is correct. SQL Server will return 2.50 and 3.60, not 2.5 and 3.6.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:24 AM
Points: 5,232,
Visits: 7,022
|
|
Mighty (10/13/2010) My opinion is that none of the answers is correct. SQL Server will return 2.50 and 3.60, not 2.5 and 3.6. Wrong! SQL Server will return a result set that consists of two columns (both datatype numeric(3,2)), and one row. The values in this row are 2.5 and 3.6. (Or 2.50 and 23.60, or 0002.500000 and 03.6000 - those are all different representations of the same numeric value).
It is your client software that converts this to a character representation so that you can see it on your screen. The client software chooses to represent these values with one trailing zero. (To check this, open an access project, create a pass-through query to execute this query on SQL Server, and heck the results. They'll show as 2.5 and 3.6. Or in my case as 2,5 and 3,6, since I have a Dutch version of Access, and the Dutch, like many other Europeans, use a decimal comma rather than a decimal point)
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 4:56 AM
Points: 1,256,
Visits: 4,253
|
|
| I had a suspicion the answer would be different, so I looked up the Access ROUND() function--didn't realise it did round-to-even before! At school I'm pretty sure we were always taught to round up (e.g. rounding -2.45 to 1 decimal place would become -2.4), though. (That was the best part of 30 years ago and my memory may be faulty on that point, though!).
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 7:36 AM
Points: 2,716,
Visits: 981
|
|
Wrong! SQL Server will return a result set that consists of two columns (both datatype numeric(3,2)), and one row. The values in this row are 2.5 and 3.6. (Or 2.50 and 23.60, or 0002.500000 and 03.6000 - those are all different representations of the same numeric value).
I don't agree with what you say.
For me it's not about what is shown on the screen, but what is returned. SQL Server returns a decimal(3, 2), as you stated. So it will not store 2.5 or 2.500, which have a different precision, but exactly 2.50.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 1,356,
Visits: 4,761
|
|
| I got this right because we've been bitten by the same thing with VB6, which also uses bankers rounding. We had to write our own rounding method to get it to round 'properly'.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 12:46 AM
Points: 2,655,
Visits: 717
|
|
Hugo Kornelis (10/13/2010)
It is your client software that converts this to a character representation so that you can see it on your screen. The client software chooses to represent these values with one trailing zero. (To check this, open an access project, create a pass-through query to execute this query on SQL Server, and heck the results. They'll show as 2.5 and 3.6. Or in my case as 2,5 and 3,6, since I have a Dutch version of Access, and the Dutch, like many other Europeans, use a decimal comma rather than a decimal point) I'd just like to point out that it isn't the version of Access that determines what decimal separator you get, it's the regional settings in the Control Panel.
Just because you're right doesn't mean everybody else is wrong.
|
|
|
|