5 Replies Latest reply: Sep 3, 2009 7:10 AM by 647770

# Integer division

Hi,
How can I get the rest of an integer division?
I have two number valiues: 7 and 3.

I would 7 / 3 = 2 and not 2.3333333333333333333333

Thanks, bye bye.
• ###### 1. Re: Integer division
``````SQL> select trunc(7/3) as result
2  from dual;

RESULT
----------
2

SQL> select cast(7/3 as number(2,0)) as result
2  from dual;

RESULT
----------
2``````
• ###### 2. Re: Integer division
Oh, another...
``````SQL> select floor(7/3) as result
2  from dual;

RESULT
----------
2``````
• ###### 3. Re: Integer division
Looks like you want TRUNC. But depending on your actuall needs you can use TRUNC, ROUND, FLOOR or CEIL:
``````SQL> select trunc(7/3),round(7/3),floor(7/3),ceil(7/3) from dual
2  /

TRUNC(7/3) ROUND(7/3) FLOOR(7/3)  CEIL(7/3)
---------- ---------- ---------- ----------
2          2          2          3

SQL> ``````
SY.
• ###### 4. Re: Integer division
>

CAST is equivalent to ROUND, not TRUNC:
``````SQL> select trunc(8/3),cast(8/3 as number(2,0)) from dual
2  /

TRUNC(8/3) CAST(8/3ASNUMBER(2,0))
---------- ----------------------
2                      3

SQL> ``````
SY.
• ###### 5. Re: Integer division
Thank everybody.
Bye bye