[英]trunc and round function in sql
trunc和round具有否定參數是否相同?
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
不,行為取決於有效數字的值(在您的情況下,第3個數字(3)是有效數字,因為它在5 round
以下並且trunc
相同)
嘗試select trunc(125456.76,-4) from dual
(結果為120000)中select trunc(125456.76,-4) from dual
vs select round(125456.76,-4) from dual
(結果為130000)中select round(125456.76,-4) from dual
)。 現在,當有效數字為5(或更高)時, trunc
和round
入的結果將不同。
ROUND
與給定值的整數相關。
TRUNC
與給定值的截斷有關。
在給定示例的round
情況下,在小數點之前的4位到第4位填充0。
但是在trunc
情況下,小數點前的第4位到第4位替換為0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.