Python SQLAlchemy 十进制精度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27869239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:23:13  来源:igfitidea点击:

SQLAlchemy decimal precision

pythonsqlalchemy

提问by Darc Nawg

The documentation at sqlalchemy gives an example:

sqlalchemy 的文档给出了一个例子:

class sqlalchemy.types.DECIMAL(precision=None, scale=None, asdecimal=True)

What values other than None can you use for precision? I don't really understand how to set up the decimal precision.

除了 None 之外,还有哪些值可以用于精度?我真的不明白如何设置小数精度。

采纳答案by Leandro Carracedo

From documentation

文档

precision– the numeric precision for use in DDL CREATE TABLE

precision– 用于 DDL CREATE TABLE 的数字精度

If you want to know which values are possible, check W3Schools for SQL data types: http://www.w3schools.com/sql/sql_datatypes_general.asp

如果您想知道哪些值是可能的,请查看 W3Schools 以获取 SQL 数据类型:http: //www.w3schools.com/sql/sql_datatypes_general.asp

In this case:

在这种情况下:

DECIMAL(p,s): Exact numerical, precision p, scale s. Example: decimal(5,2) is a number that has 3 digits before the decimal and 2 digits after the decimal

DECIMAL(p,s):精确数值,精度 p,小数位数。示例:decimal(5,2) 是一个小数点前有 3 位数字,小数点后有 2 位数字的数字