Products Downloads


French version


 

 

Syntax

MODULO(Argument1,Argument2)

 

Description

The MODULO SQL scalar function divides the first argument by the second argument and returns the remainder.

 

The formula used to calculate the remainder is:

 

MODULO(x,y) = x - (x/y) * y

 

where x/y is the truncated integer result of the division.

 

The arguments must be numbers. The second argument cannot be zero.

If an argument can be null, the result can be null; if an argument is null, the result is the null value.

 

The operation is performed in floating point; the operands having been first converted to double-precision floating-point numbers, if necessary.

An operation involving a floating-point number and an integer is performed with a temporary copy of the integer that has been converted to double-precision floating point.

An operation involving a floating-point number and a decimal number is performed with a temporary copy of the decimal number that has been converted to double-precision floating point.

The result of a floating-point operation must be within the range of floating-point numbers.

 

Example

First case:

Assume the column M1 is an integer column with a value of 5, and column M2 is an integer column with a value of 2.

 

MODULO(M1,M2)

 

Returns the value 1.

 

Second case:

Assume the column M1 is an integer column with a value of 5, and column M2 is a decimal(3,1) column with a value of 2.2.

 

MODULO(M1,M2)

 

Returns the value 0.6.

 

Third case:

Assume the column M1 is an integer column with a value of 5, and column M2 is a decimal(3,2) column with a value of 2.20.

 

MODULO(M1,M2)

 

Returns the value 0.60.

 

Fourth case:

Assume the column M1 is a decimal(4,2) column with a value of 5.50, and column M2 is a decimal(4,1) column with a value of 2.0.

 

MODULO(M1,M2)

 

Returns the value 1.50.

 

List of SQL scalar functions by topic

 

↑ Top of page

  • Aucune étiquette