How to rounding up in oracle

4.9k views Asked by At

I want to convert this value "2167.124" to "2167.13" using round function in oracle 11g. Problem is that it converts LIKE "2167.12" But i need "2167.13".

Please help, Thanks in advance

2

There are 2 answers

1
Sam On BEST ANSWER

If you want to convert given value 2167.12" to "2167.13" Please use this

select ceil(2167.124*100)/100 from dual;

0
Alex Poole On

Expanding on Sam's example, multiplying by 100 effectively moves the decimal point two places to the right, so your value becomes 216712.4:

select 2167.124*100 as step1 from dual;

     STEP1
----------
  216712.4

You then call ceil on that, to find "the smallest integer that is greater than or equal to n":

select ceil(216712.4) as step2 from dual;

     STEP2
----------
    216713

Then dividing by 100 effectively moves the decimal point back the same two places to the left:

select 216713/100 as step3 from dual;

     STEP3
----------
   2167.13

Putting the three steps together into one statement gets:

select ceil(2167.124*100)/100 as result from dual;

    RESULT
----------
   2167.13