In PL/SQL, the MOD()
returns some unexpected values. MOD(23,2)
which is expected to return 1
actually returns 0
.
MOD(29,2)
also returns 0
, I think the problem is that it uses the float values.
Is there any alternative to MOD()
?
In PL/SQL, the MOD()
returns some unexpected values. MOD(23,2)
which is expected to return 1
actually returns 0
.
MOD(29,2)
also returns 0
, I think the problem is that it uses the float values.
Is there any alternative to MOD()
?
Alternative ?
Mod is:
x - y * floor(x/y)
so:
23 - 2 * 11 = 1 --(23/2 = 11,5 --> 'round down' = 11)
29 - 2 * 14 = 1 --(29/2 = 14,5 --> 'round down' = 14)
Good to know:
The function to 'round up' is CEIL, but it generates an integer.
The function to 'round down' is FLOOR, but it too generates an integer.
The function to 'round nearest' is ROUND, and it allows you to specify a number of decimal places (dp).
Note that CEIL rounds to an integer; to round to 2 dp, you'd have to multiply by 100, use CEIL, and divide by 100.