關於postgresql中numeric和decimal的精度和標度問題


精度即數的有效數字個數

2.5的有效數字個數是2,但是053.2的有效數字個數是3

標度是小數點的位數

例如numeric(2,1),即這個數必須是兩位,並且小數后面最多有一位,多出來的小數會被四舍五入

可以很容易的確定出numeric的范圍,即-10(精度-標度)到10(精度-標度)次方之間,不包括兩頭

create table test (num numeric(2,1));
insert into test values (2.2);
 num 
-----
 2.2
insert into test values (2.26);
 num 
-----
 2.3
insert into test values (10);
ERROR:  numeric field overflow
DETAIL:  A field with precision 2, scale 1 must round to an absolute value less than 10^1.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM