Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Round


Round

Author
Message
Pradyothana Shastry
Pradyothana Shastry
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1702 Visits: 481
Comments posted to this topic are about the item Round


- Pradyothana


http://www.msqlserver.com
tommyh
tommyh
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1560 Visits: 2000
Nice question. Though the explanation isnt entirely accurate. Its not rounded, its truncated.

If the question had been, lets say

declare @r decimal(5,2)
set @r= round(5/3.2,1,3)
select @r


Then we would get 1.5 wheras a round would have given us 1.6 (change last parameter in Round to 0... or remove it all together).
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21105 Visits: 18259
thanks for the question



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

honza.mf
honza.mf
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1771 Visits: 1323
tommyh (9/16/2010)
Nice question. Though the explanation isnt entirely accurate. Its not rounded, its truncated.

If the question had been, lets say

declare @r decimal(5,2)
set @r= round(5/3.2,1,3)
select @r


Then we would get 1.5 wheras a round would have given us 1.6 (change last parameter in Round to 0... or remove it all together).


Right, the 3rd parameter of round is the most important one. It's value 3 is not typical but greater than zero.



See, understand, learn, try, use efficient
© Dr.Plch
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16509 Visits: 13207
Good question, but a real easy one since all the rounding questions of Hugo Kornelis. :-)

It would've been more a challenge if you used 3.2 or 3.0, as someone already suggested in this thread.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
cengland0
cengland0
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1484 Visits: 1300
I got it right but hesitated to click the submit button. It was too easy and I was looking for the tricky part of the question. I've been bitten by so many QOTDs with an obscure typo or something else tricky.
Daniel Bowlin
Daniel Bowlin
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2954 Visits: 2629
Good question. Round is a function with a few gotchas that it is important to know about and understand. Thanks.
Dave62
Dave62
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3060 Visits: 2716
cengland0 (9/17/2010)
... I've been bitten by so many QOTDs with an obscure typo or something else tricky.


I like composing questions that are on the tricky side. Must be because of all my bad experiences with certification exams.

If it's of any consolation, the editors here do have a limit to what they will tolerate for trick questions. I submitted one a few months ago that never got published.

I get it. The QOTDs are more about the learning experience than the certification experience.

I'm working on one now that's a little more tame... :-)
hrvoje.piasevoli
hrvoje.piasevoli
Old Hand
Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)

Group: General Forum Members
Points: 365 Visits: 510
The hardest part of the question was figuring out what is the result of 5/3.1
IMHO the point of the question would make more sense if it had been changed to 5/3.0 as the result of the function would actually be affected by the third parameter of the ROUND function unlike in this question.
To illustrate:
select 
Example = 'Your example'
,input_data = '5/3.1'
,Truncation = ROUND(1.612903, 1, 1) -- 1.600000
,Rounding = ROUND(1.612903, 1, 0) -- 1.600000
union all
select
'Better example'
,'5/3.0'
,ROUND(1.666666,1,1) -- 1.600000
,ROUND(1.666666,1,0) -- 1.700000


Example        input_data Truncation   Rounding
-------------- ---------- ------------ ----------
Your example 5/3.1 1.600000 1.600000
Better example 5/3.0 1.600000 1.700000


Regards,
Hrvoje Piasevoli

Hrvoje Piasevoli
john.arnott
john.arnott
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1474 Visits: 3059
honza.mf (9/17/2010)
tommyh (9/16/2010)
Nice question. Though the explanation isnt entirely accurate. Its not rounded, its truncated.

If the question had been, lets say

declare @r decimal(5,2)
set @r= round(5/3.2,1,3)
select @r


Then we would get 1.5 wheras a round would have given us 1.6 (change last parameter in Round to 0... or remove it all together).


Right, the 3rd parameter of round is the most important one. It's value 3 is not typical but greater than zero.

Just to be picky, it's not because the third parameter is greater than zero, but because it is not equal to zero. Here's the entry in BOL for SQL 2005:
Syntax

ROUND ( numeric_expression , length [ ,function ] )


Arguments
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.

length
Is the precision to which numeric_expression is to be rounded. length must be tinyint, smallint, or int. When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.

function
Is the type of operation to perform. function must be tinyint, smallint, or int. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search