Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
570 views
in Technique[技术] by (71.8m points)

How to use SQLite decimal precision notation

Again I find myself frustrated by the awful SQLite documentation.

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to http://www.sqlite.org/datatype3.html

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

(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.)

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

According to http://www.sqlite.org/datatype3.html

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...