如何解释数据库中数字的精度和小数位数? [英] How do I interpret precision and scale of a number in a database?

查看:24
本文介绍了如何解释数据库中数字的精度和小数位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中指定了以下列:decimal(5,2)

I have the following column specified in a database: decimal(5,2)

人们如何理解这一点?

根据在 SQL Server Management Studio 中查看的列上的属性,我可以看到它的意思是:decimal(Numeric precision, Numeric scale).

According to the properties on the column as viewed in SQL Server Management studio I can see that it means: decimal(Numeric precision, Numeric scale).

精度和规模的实际含义是什么?

What do precision and scale mean in real terms?

很容易将其解释为具有 5 位数字和两位小数的小数...即 12345.12

It would be easy to interpret this as a decimal with 5 digits and two decimals places...ie 12345.12

附言我已经能够从一位同事那里确定正确答案,但在网上找到答案非常困难.因此,我希望将问题和答案记录在 stackoverflow 上以备将来参考.

P.S. I've been able to determine the correct answer from a colleague but had great difficulty finding an answer online. As such, I'd like to have the question and answer documented here on stackoverflow for future reference.

推荐答案

数字精度是指数字中存在的最大位数.

Numeric precision refers to the maximum number of digits that are present in the number.

即 1234567.89 的精度为 9

ie 1234567.89 has a precision of 9

数字小数位数是指最大小数位数

Numeric scale refers to the maximum number of decimal places

即 123456.789 的比例为 3

ie 123456.789 has a scale of 3

因此,decimal(5,2) 的最大允许值为 999.99

Thus the maximum allowed value for decimal(5,2) is 999.99

这篇关于如何解释数据库中数字的精度和小数位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆