w3resource

Oracle REMAINDER() function

Description

This function returns the remainder of n2 divided by n1. n1 and n2 are the arguments of this function.

The MOD function is similar to REMAINDER except that the MOD uses FLOOR in its formula, whereas REMAINDER uses ROUND.

Syntax:

REMAINDER(n2, n1)

Rules:

  • When n1 = 0 or n2 = infinity, then returns an error if the type of arguments are NUMBER and NaN if the types of arguments are BINARY_FLOAT or BINARY_DOUBLE.
  • When n1 != 0, then the remainder is n2 - (n1*N) where N is the integer nearest n2/n1. If n2/n1 equals x.5, then N is the nearest even integer.
  • When n2 is a floating-point number, and if the remainder is 0, then the sign of the remainder is the sign of n2. Remainders of 0 are unsigned for NUMBER values.

Example

We have a sample table float_point_test with three columns, dec_num, type 'NUMBER(10,2)', bin_double, type 'BINARY_DOUB LE' and bin_float, type 'BINARY_FLOAT'. Here is the table.

SQL> SELECT * FROM float_point_test;

   DEC_NUM BIN_DOUBLE  BIN_FLOAT
---------- ---------- ----------
   1513.67 1.514E+003 1.514E+003

The example below divides two floating-point numbers and returns the remainder of that operation using the float_point_test table.

SELECT bin_float, bin_double, REMAINDER(bin_float, bin_double) 
FROM float_point_test;

Here is the result.

 BIN_FLOAT BIN_DOUBLE REMAINDER(BIN_FLOAT,BIN_DOUBLE)
---------- ---------- -------------------------------
1.514E+003 1.514E+003                        1.0E-001

Previous: POWER
Next: ROUND



Follow us on Facebook and Twitter for latest update.