Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SQL> select round(1234.56789,2) from dual;
ROUND(1234.56789,2)
-------------------
1234.57
SQL> select floor(1234.56789) from dual;
FLOOR(1234.56789)
-----------------
1234
SQL> select ceil(1234.56789) from dual;
CEIL(1234.56789)
----------------
1235
SQL> select trunc(1234.56789,2) from dual;
TRUNC(1234.56789,2)
-------------------
1234.56
create or replace function bankers_round (val number, rnd_digit number) return number is
begin
if val = trunc(val,rnd_digit+1) and mod(substr(trunc(val,rnd_digit),-1),2) = 0 then
return trunc(val,rnd_digit);
else
return round(val,rnd_digit);
end if;
end;
/
Function created.
select bankers_round(123.4550001,2) from dual;
BANKERS_ROUND(123.4550001,2)
----------------------------
123.46
select bankers_round(123.4450001,2) from dual;
BANKERS_ROUND(123.4450001,2)
----------------------------
123.45
select bankers_round(123.445,2) from dual;
BANKERS_ROUND(123.445,2)
------------------------
123.44
select bankers_round(123.455,2) from dual;
BANKERS_ROUND(123.455,2)
------------------------
123.46
select bankers_round(123.5,0) from dual;
BANKERS_ROUND(123.5,0)
----------------------
124
select bankers_round(124.5,0) from dual;
BANKERS_ROUND(124.5,0)
----------------------
124
create or replace function bankers_round (val number, rnd_digit number := 0) return number is
v_rnd_digit number;
v_remainder number;
begin
v_rnd_digit := trunc(rnd_digit);
v_remainder := (val - trunc(val,v_rnd_digit)) * power(10,v_rnd_digit + 1);
if v_remainder < 5
or (v_remainder = 5 and mod(trunc(val * power(10,v_rnd_digit)),2) = 0) then
return trunc(val,v_rnd_digit);
else
return round(val,v_rnd_digit);
end if;
end;
/
SQL> select bankers_round(14.5) from dual
BANKERS_ROUND(14.5)
-------------------
14
SQL> select bankers_round(14.51) from dual
BANKERS_ROUND(14.51)
--------------------
15
SQL> select bankers_round(13.5) from dual
BANKERS_ROUND(13.5)
-------------------
14
SQL> select bankers_round(14.45, 1.5) from dual
BANKERS_ROUND(14.45,1.5)
------------------------
14.4
SQL> select bankers_round(145, -1) from dual
BANKERS_ROUND(145,-1)
---------------------
140
SQL> select bankers_round(145.1, -1) from dual
BANKERS_ROUND(145.1,-1)
-----------------------
150
SQL> select bankers_round(135, -1) from dual
BANKERS_ROUND(135,-1)
---------------------
140
create or replace function bankers_round (val number, rnd_digit number := 0) return number is
v_rnd_digit number;
v_remainder number;
begin
v_rnd_digit := trunc(rnd_digit);
v_remainder := (val - trunc(val,v_rnd_digit)) * power(10,v_rnd_digit + 1);
if [!]Abs([/!]v_remainder[!])[/!] < 5
or ([!]Abs([/!]v_remainder[!])[/!] = 5 and mod(trunc(val * power(10,v_rnd_digit)),2) = 0) then
return trunc(val,v_rnd_digit);
else
return round(val,v_rnd_digit);
end if;
end;
/
SQL> create or replace function bankers_round (val number, rnd_digit number := 0) return number is
2 v_rnd_digit number;
3 v_remainder number;
4 begin
5 v_rnd_digit := trunc(rnd_digit);
6
7 v_remainder := (val - trunc(val,v_rnd_digit)) * power(10,v_rnd_digit + 1);
8
9 if Abs(v_remainder) < 5
10 or (Abs(v_remainder) = 5 and mod(trunc(val * power(10,v_rnd_digit)),2) = 0) then
11 return trunc(val,v_rnd_digit);
12 else
13 return round(val,v_rnd_digit);
14 end if;
15 end;
16 /
Function created.
SQL> select Bankers_Round(-123.45, 1) from dual;
BANKERS_ROUND(-123.45,1)
------------------------
-123.4
SQL> select Bankers_Round(-123.55, 1) from dual;
BANKERS_ROUND(-123.55,1)
------------------------
-123.6
SQL> select Bankers_Round(-123.65, 1) from dual;
BANKERS_ROUND(-123.65,1)
------------------------
-123.6
SQL> select Bankers_Round(-123.75, 1) from dual;
BANKERS_ROUND(-123.75,1)
------------------------
-123.8