Reputation: 2465
Is trunc and round the same with negative arguments?
SQL> select round(123456.76,-4) from dual;
ROUND(123456.76,-4)
-------------------
120000
SQL> select trunc(123456.76,-4) from dual;
TRUNC(123456.76,-4)
-------------------
120000
Upvotes: 4
Views: 19690
Reputation: 1
TRUNC
- depending on second parameter it returns specified decimal places that is specified in second argument. Ex:
trunc(25.656) -- 25
trunc(25.656, 1) -- 25.6
trunc(25.656, 2) -- 25.65
ROUND
- round off the given number to the nearest value. Ex:
round(66) -- 70
round(64) -- 60
round(65.7) -- 66
round(65.3) -- 65
Upvotes: 0
Reputation: 16310
ROUND
is related to round figure of given value.
TRUNC
is related to truncation of given values.
In round
case of given example, four places till 4th place prior to decimal point padded with 0.
But in trunc
case, four places till 4th place prior to decimal point replacd with 0.
Upvotes: 1
Reputation: 2414
No, behavior depends on the value of the significant digit (the 3rd digit (the 3) is the significant one in your case, as it is below 5 round
and trunc
do the same )
try select trunc(125456.76,-4) from dual
(result is 120000) vs select round(125456.76,-4) from dual
(result is 130000). Now when the significant digit is 5 (or higher) the results of trunc
and round
differ.
Upvotes: 10