Rounding issue

  • How do I round

    0.85415 to 1 ?

    I am getting a 0 instead .

    Thanks,

  • PSB - Thursday, March 1, 2018 10:20 AM

    How do I round

    0.85415 to 1 ?

    I am getting a 0 instead .

    Thanks,

    How are you rounding? What are the data types used?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • You mean something like this?

    DECLARE @num DECIMAL(10,5) = 0.85415;

    SELECT @num, ROUND(@num,0);

  • SELECT 10103,11828,ROUND(10103/11828,0) As results 

    -- Results coming in as 0.

  • PSB - Thursday, March 1, 2018 10:55 AM

    SELECT 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.

  • 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)

  • 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