1. Registered User
Join Date
Feb 2007
Posts
4

Code:
`Set @AVG = ROUND ((V1*5+V2*5)/10,0)`
What is the difference between these codes?

Code:
`Set @AVG = ROUND ((V1*5+V2*5)/10.0,0)`
For values V1=80, V2=85;
First code gives 82! Second gives 83!

2. Registered User
Join Date
Jan 2003
Location
Massachusetts
Posts
5,860
The first one does an implicit rounding (actually truncating), because all of the values involved are defined as integer values.

3. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595
Not strange at all, once you understand the behavior of datatypes.

In this example, only the integer portion is returned, because all parameters are integers. So rounding the result is superfluous:
Code:
`select	825/10`
Even if the result is close to the next highest integer, it is always truncated:
Code:
`select	829/10`
In this example, a decimal value is returned, since at least one parameter is a decimal datatype:
Code:
`select	825/10.00`
...and any decimal value greater than or equal to 0.5 is rounded up:
Code:
`select	round(825/10.00, 0)`

4. Village Idiot
Join Date
Jul 2003
Location
Michigan
Posts
1,941
Have a look at "Precision, Scale, and Length" in BOL. It gives a pretty good explanation... one that even I could understand.

5. Registered User
Join Date
Feb 2007
Posts
4
Thanx.
using A/10 instead of A/10.0 wiped out someones confidence on me...

6. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595
Tell them you were only off by zero.

7. Registered User
Join Date
Feb 2007
Posts
4
Originally Posted by blindman
Tell them you were only off by zero.
Thanx

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•