# Thread: Round & Trunc function in oracle

1. Registered User
Join Date
Jul 2007
Posts
5

## Unanswered: Round & Trunc function in oracle

Hi,

I got a book of oracle and reading functions round and trunc.

They are given as

round(14.236,2) This number is rounded to 14.24
but
round(45.862,-1) is rounded as 50
(How it is so)

Same as;;;;;;;
trunc(45.862,0) This number is trunc to 45
but
trunc(45.862,-1) is trunc to 40
(How it is so)

Please Suggest me, how it happens .........in - (minus) case

Katie

2. Lost Boy
Join Date
Jan 2004
Location
Croatia, Europe
Posts
4,113
In "minus" case:
ROUND: digits LEFT of the decimal point are rounded
TRUNC: digits LEFT of the decimal point are truncated (i.e. made zero)

3. Registered User
Join Date
Aug 2004
Location
France
Posts
754
The general behaviour of ROUND(nb, m) and TRUNC(nb, m) is :
Code:
```ROUND(nb, m) = ROUND(nb*10^m) * 10^-m

TRUNC(nb, m) = TRUNC(nb*10^m) * 10^-m```
The behaviour with m = -1 is :

Code:
```ROUND(45.8, -1) = ROUND(45.8*10^-1) * 10^1 = ROUND(4.58) * 10 = 5 * 10 = 50

TRUNC(45.8, -1) = TRUNC(45.8*10^-1) * 10^1 = TRUNC(4.58) * 10 = 4 * 10 = 40```
And with m = 2 :

Code:
```ROUND(14.236, 2) = ROUND(14.236*10^2) * 10^-2 = ROUND(1423.6) * 0.01 = 1424 * 0.01 = 14.24

TRUNC(14.236, 2) = TRUNC(14.236*10^2) * 10^-2 = TRUNC(1423.6) * 0.01 = 1423 * 0.01 = 14.23```
This is just mathematics

Regards,

rbaraer

4. Registered User
Join Date
Dec 2003
Location
Oklahoma, USA
Posts
354
MATH! Hey nobody said anything about using math!

By the way RBARAER, great explanation!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•