February 10, 2011 at 5:43 pm
I cannot believe I am having this much trouble with rounding.
Why doesn't
select round(5/2,0)
result in a 3?
or this
select round(5/2,1)
result in a 2.5?
I know this is pathetic. I've been trying to work on a formula in my code and I had to keep simplifying to make sure I understood exactly what's happening. And I got down to THAT simple and I am still confused.
February 10, 2011 at 6:29 pm
the integer division, 5,2 is evaluated before the round occurs.
if you divide two integers in SQL, the result is returned in the same datatype...an integer.
That behavior is kind of unique to SQL; you do not see that in programming languages.
to get 2.5-->3.0 , you have to cast/convert at least one of the two numbers to a decimal
select round(5/2,0),round(5.0/2,0)
Lowell
February 11, 2011 at 8:39 am
Thank you Lowell!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply