简体   繁体   English

精度和比例有什么区别?

[英]What is the difference between precision and scale?

What is the difference between precision and scale in Oracle? Oracle的精度和小数位数有什么区别? In tutorials they usually leave scale empty and set precision to 6 when creating a primary key.在教程中,他们通常在创建主键时将比例留空并将精度设置为 6。

What do precision and scale stand for?精度和规模代表什么?

Precision 4, scale 2: 99.99精度 4,刻度 2:99.99

Precision 10, scale 0: 9999999999精度 10,比例 0:9999999999

Precision 8, scale 3: 99999.999精度 8,刻度 3:99999.999

Precision 5, scale -3: 99999000精度 5,刻度 -3:99999000

Precision is the number of significant digits.精度是有效数字的位数。 Oracle guarantees the portability of numbers with precision ranging from 1 to 38. Oracle 以 1 到 38 的精度保证数字的可移植性。

Scale is the number of digits to the right (positive) or left (negative) of the decimal point.小数位数是小数点右侧(正)或左侧(负)的位数。 The scale can range from -84 to 127.范围可以从 -84 到 127。

In your case, ID with precision 6 means it won't accept a number with 7 or more significant digits.在您的情况下,精度为 6 的 ID 意味着它不会接受具有 7 个或更多有效数字的数字。

Reference:参考:

http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832 http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832

That page also has some examples that will make you understand precision and scale.该页面还有一些示例,可以让您了解精度和比例。

Precision is the total number of digits, can be between 1 and 38.精度是总位数,可以在 1 到 38 之间。
Scale is the number of digits after the decimal point, may also be set as negative for rounding.规模是小数点后的数字位数,也可以被设置为负舍入。

Example:例子:
NUMBER(7,5): 12.12345号码(7,5):12.12345
NUMBER(5,0): 12345号码(5,0):12345

More details on the ORACLE website: ORACLE 网站上的更多详细信息:
https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832 https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832

Maybe more clear:也许更清楚:

Note that precision is the total number of digits, scale included请注意,精度是总位数,包括小数位数

NUMBER(Precision,Scale) NUMBER(精度,刻度)

Precision 8, scale 3 : 87654.321精度 8,刻度 3:87654.321

Precision 5, scale 3 : 54.321精度 5,刻度 3:54.321

Precision 5, scale 1 : 5432.1精度 5,刻度 1:5432.1

Precision 5, scale 0 : 54321精度 5,刻度 0:54321

Precision 5, scale -1: 54320精度 5,比例 -1:54320

Precision 5, scale -3: 54000精度 5,比例 -3:54000

Scale is the number of digit after the decimal point (or colon depending your locale)比例是小数点后的位数(或冒号,取决于您的语言环境)

Precision is the total number of significant digits精度是有效数字的总数

规模 VS 精度

precision: Its the total number of digits before or after the radix point.精度:小数点前后的总位数。 EX: 123.456 here precision is 6.例如:123.456 这里的精度是 6。

Scale: Its the total number of digits after the radix point.小数位数:小数点后的总位数。 EX: 123.456 here Scaleis 3 EX: 123.456 这里 Scaleis 3

  • Precision: Total length of the data.精度:数据的总长度。
  • Scale规模
    • Scale>0规模>0

      • Precision=Integer.Length+Decimal.Length精度=整数.长度+小数.长度
      • The number of digits after the decimal point.小数点后的位数。
    • Scale<0规模<0

      • Precision=Integer.Length精度=整数.长度

      If you specify a negative scale, Oracle Database rounds the actual data to the specified number of places to the left of the decimal point.如果您指定负比例,Oracle 数据库会将实际数据四舍五入到小数点左侧的指定位数。 Reference to Oracle 参考Oracle

If value is 9999.988 and Precision 4, scale 2 then it means 9999(it represents precision).99(scale is 2 so .988 is rounded to .99)如果值为 9999.988 且精度为 4,比例为 2,则表示 9999(表示精度)。99(比例为 2,因此 .988 舍入为 0.99)

If value is 9999.9887 and precision is 4, scale is 2 then it means 9999.99如果值为 9999.9887,精度为 4,小数位数为 2,则表示 9999.99

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM