如何使用 SQLite 十进制精度表示法 [英] How to use SQLite decimal precision notation

查看:25
本文介绍了如何使用 SQLite 十进制精度表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次我发现自己对糟糕的 SQLite 文档.

Again I find myself frustrated by the awful SQLite documentation.

http://www.sqlite.org/datatype3.html 给出了一个定义的例子decimal(10,5) 的十进制字段,但它没有解释什么是 10,什么是 5.

http://www.sqlite.org/datatype3.html gives an example of defining a decimal field as decimal(10,5) but it doesn't explain what 10 is and what 5 is.

我确定 10 是存储的总位数,但我不知道 5 是什么意思.是小数点之前还是小数点之后的位数?

I am sure that 10 is the total number of digits stored, but I don't know what 5 means. Is it the number of digits before the decimal place or after the decimal place?

推荐答案

根据 http://www.sqlite.org/datatype3.html

[decimal 是几个] 来自更传统 SQL 实现的常见数据类型名称是转换为 [SQLite] 亲和力

[decimal is one of several] common datatype names from more traditional SQL implementations are converted into [SQLite] affinities

(亲缘关系与 SQLite 具有的数据类型的概念差不多.阅读 http:///www.sqlite.org/datatype3.html 了解更多相关信息.)

(An affinity is about as close to the idea of a data type that SQLite has. Read http://www.sqlite.org/datatype3.html for more about this.)

按照这个逻辑,使用 MySQL 的文档来解释 SQLite 十进制精度表示法似乎是安全的.

By this logic, it seems safe to use the documentation from MySQL to explain the SQLite decimal precision notation.

根据http://www.sqlite.org/datatype3.html

标准 SQL 要求 DECIMAL(5,2) 能够存储任何值有五位数字和两位小数,因此可以存储在薪水列范围从 -999.99 到 999.99.

Standard SQL requires that DECIMAL(5,2) be able to store any value with five digits and two decimals, so values that can be stored in the salary column range from -999.99 to 999.99.

所以 decimal(10,5) 表示该字段应该用于存储长度最多为十位的值,小数点前最多五位,小数点后最多五位小数点.

So decimal(10,5) indicates that the field should be used to store a value up to ten digits in length, with up to five digits before the decimal point and up to five digits after the decimal point.

当然,任何输入的值都会被存储,即使它不遵守这些规则,这意味着字段定义基本上是文档.

Of course, any value entered will be stored, even if it doesn't keep to these rules, which means that the field definition is basically documentation.

这篇关于如何使用 SQLite 十进制精度表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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