原文:
Precision
The precision specifies the total number of digits. If a precision is not specified, then the column stores the values exactly as provided by the application without any rounding.
Scale
The scale specifies the number of digits from the decimal point to the least significant digit. Positive scale counts digits to the right of the decimal point up to and including the least significant digit. Negative scale counts digits to the left of the decimal point up to but not including the least significant digit. If you specify a precision without a scale, as in NUMBER(6), then the scale is 0.
number(p,s) p:1~38 s:-84~127
P可以理解为有效数位 :从左边第一个不为 0 的数算起,到末位数字为止的所有数字,小数点和负号不计入有效位数。
S为从哪一位开始进行四舍五入。
number(p,s) p:1~38 s:-84~127
最高整数位数=p-s
s正数,小数点右边指定位置开始四舍五入
s负数,小数点左边指定位置开始四舍五入
s是0或者未指定,四舍五入到最近整数
当p小于s时候,表示数字是绝对值小于1的数字,且从小数点右边开始的前s-p 位必须是0,保留s位小数。
p>0,对s分2种情况:
1. s>0
精确到小数点右边s位,并四舍五入。然后检验有效数位是否<=p;如果s>p,小数点右边至少有s-p个0填充。
2. s<0
精确到小数点左边s位,并四舍五入。然后检验有效数位是否<=p+|s|
比如
Value Datatype Stored Value
123.2564 NUMBER 123.2564
1234.9876 NUMBER(6,2) 1234.99
12345.12345 NUMBER(6,2) Error
1234.9876 NUMBER(6) 1235
12345.345 NUMBER(5,-2) 12300
1234567 NUMBER(5,-2) 1234600
12345678 NUMBER(5,-2) Error
123456789 NUMBER(5,-4) 123460000
1234567890 NUMBER(5,-4) Error
12345.58 NUMBER(*, 1) 12345.6
0.1 NUMBER(4,5) Error
0.01234567 NUMBER(4,5) 0.01235
0.09999 NUMBER(4,5) 0.09999
0.099996 NUMBER(4,5) <>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28826508/viewspace-1369274/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28826508/viewspace-1369274/