March 1, 2018 at 10:20 am
How do I round
0.85415 to 1 ?
I am getting a 0 instead .
Thanks,
March 1, 2018 at 10:26 am
PSB - Thursday, March 1, 2018 10:20 AMHow do I round0.85415 to 1 ?
I am getting a 0 instead .
Thanks,
How are you rounding? What are the data types used?
March 1, 2018 at 10:42 am
You mean something like this?
DECLARE @num DECIMAL(10,5) = 0.85415;
SELECT @num, ROUND(@num,0);
March 1, 2018 at 10:55 am
SELECT 10103,11828,ROUND(10103/11828,0) As results
-- Results coming in as 0.
March 1, 2018 at 10:59 am
PSB - Thursday, March 1, 2018 10:55 AMSELECT 10103,11828,ROUND(10103/11828,0) As results
-- Results coming in as 0.
You are doing integer math, that is why you are getting 0. Add a .0 to one of the numbers.
March 1, 2018 at 11:05 am
As Lynn points out, you are effectively using integer division, which will occur BEFORE the ROUND function has a chance to operate. Whenever you are specifying a constant, and need a decimal result of division, be sure the divisor has a decimal point.
Try this:SELECT 10103, 11828, ROUND(10103 / 11828., 0) As results
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
March 1, 2018 at 11:19 am
Great. Thanks! It worked . 🙂
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply