Integers: The Above Example Rounds Decimal Portions From 3 Digits (.193) To One Decimal Point (.2)
Round() works differently for integers and dates. For integers, it rounds decimal portions to a specified number of digits by using round(number, n) where n is the number of decimal places. For negative n, it rounds the number of places to the left of the decimal point. For dates, round() rounds to the start of the specified unit like year, month, or day.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
24 views
Integers: The Above Example Rounds Decimal Portions From 3 Digits (.193) To One Decimal Point (.2)
Round() works differently for integers and dates. For integers, it rounds decimal portions to a specified number of digits by using round(number, n) where n is the number of decimal places. For negative n, it rounds the number of places to the left of the decimal point. For dates, round() rounds to the start of the specified unit like year, month, or day.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
round():
it works differently for integers and dates
Integers It rounds decimal portions to specified number of digits... synatx: round(decimal number, n), where n specified no of decimal portions to show Ex: SELECT ROUND(15.193,1) "Round" FROM DUAL;
Round ---------- 15.2
the above example rounds decimal portions from 3 digits (.193) to one decimal point(.2)
SELECT ROUND(1.5), ROUND(2.5) FROM DUAL;
ROUND(1.5) ROUND(2.5) ---------- ---------- 2 3 in the above example, we have not specified the 'n' value in round function ...round(number, n), in this case it removes decimal portion and rounds the number to nearest Integer here 1.5 is nearst to 2, so result is 2 and 2.5 is nearest to 3 if we specifiy 1.4, we will get answer as 1.
The following example rounds a number one digit to the left of the decimal point: SELECT ROUND(15.193,-1) "Round" FROM DUAL;
Round ---------- 20 if we specify - values in 'n' portion as ..round(number, -n), then it completely removes decimal portion and rounds the specified digits by -n if you take round(15.193,-1), first it removes decimal portion, so result is 15, and -1 round first digit from right side, i.e 5, 5 is more than or equal to 5 so it adds 1 to preceded digit, that is 1 5 1+1 0 =2 0 SELECT ROUND(315.193,-1) "Round" FROM DUAL;
Round ----------- 320
SELECT ROUND(335.193,-2) "Round" FROM DUAL;
Round ---------- 300 the operation is done for two digits from the right side as we have given -2 first digit operation 3 3 5 (5>=5 so adds 1 to preceded number and 5 becomes 0 ) 3 3+1 0 =3 4 0 second digit operation 3 4 (4<=5 so no number added to preceded digit and 4 becomes to 0) 0 3 0 0
Round function Examples on Date The following example rounds a date to the first day of the following year: SELECT ROUND (TO_DATE ('27-OCT-00'),'YEAR') "New Year" FROM DUAL;