Help understanding round function
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Help understanding round function

Hybrid View

  1. #1
    Join Date
    Jun 2001
    Posts
    33

    Question

    New to oracle. I do not get the concept of round function. It seems to be silly.

    select round(50.989, -2) from dual ;
    gives the result as 100.

    select round(50.989, -1) from dual;
    gives the result as 50.

    I think I didn't understand the definition properly.

    When I give select round(12.989, -1) from dual;
    gives 10.

    could somone kindly explain this.

    thank you
    nath


  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  3. #3
    Join Date
    May 2001
    Location
    San Francisco, California
    Posts
    510
    Let me try to explain this:
    In the round function, if you give a posivite integer n, it rounds n places to the right of the decimal place.

    SQL> select round (1.11, 1) from dual;

    ROUND(1.11,1)
    -------------
    1.1

    SQL> select round(1.16, 1) from dual;

    ROUND(1.16,1)
    -------------
    1.2

    If you give 0, it rounds to 0 places.

    SQL> select round(1.500000000001,0) from dual;

    ROUND(1.500000000001,0)
    -----------------------
    2

    The next higher integer for 1.500000000001 with no decimal places is 2.

    If you give negative values, it starts rounding the left hand side of the decimal, that is

    SQL> select round(155.001, -1) from dual;

    ROUND(155.001,-1)
    -----------------
    160

    Since we use 10 based number system, for -1 anything over the 5 mark becomes next higher 10. For -2, anything over 51 becomes next 100;

    SQL> select round(150.001, -2) from dual;

    ROUND(150.001,-2)
    -----------------
    200

    for -3, anything over 500 becomes, next 1000 etc., This why if you try to round 155 to -3 digits you will get zero.

    SQL> select round(155.001, -3) from dual;


    ROUND(155.001,-3)
    -----------------
    0



Posting Permissions

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


Click Here to Expand Forum to Full Width