The comparison between the round () function and trunc () function in Oracle is very practical.
The comparison between the round () function and trunc () function in Oracle is very practical.
In Oracle, the round () function is very useful compared with the trunc () function.
Round (x [, y])
[Function] returns the rounded value.
[Parameter] x, y, numeric expression. If y is not an integer, the y integer is truncated. If y is greater than 0, the rounding is y decimal, if y is less than 0, it is rounded to the y place to the left of the decimal point.
Return number
[Example] select round (5555.6666, 2.1), round (5555.6666,-2.6), round (5555.6666) from dual;
Return Value: 5555.67, 5600,555 6
[Close] trunc (x [, y]) returns the truncated value, which is used in the same way as round (x [, y]), but is not rounded down.
Trunc (x [, y])
[Function] returns the value after x is truncated by y.
[Parameter] x, y, numeric expression. If y is not an integer, the y integer is truncated. If y is greater than 0, the y decimal is truncated, if y is less than 0, the decimal point is truncated to the y-th place on the left. Other data before the decimal point is represented by 0.
Return number
[Example] select trunc (5555.66666, 2.1), trunc (5555.66666,-2.6), trunc (5555.033333) from dual;
Return Value: 5555.66 5500 5555
[Close] round (x [, y]) returns the value after the truncation. The usage is the same as that of trunc (x [, y]), but only rounding