如何使用 phpMyAdmin 在 MySQL 中指定小数精度和小数位数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23877487/
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-31 20:34:07  来源:igfitidea点击:

How to specify decimal precision and scale number in MySQL using phpMyAdmin

mysqlsqlphpmyadmin

提问by Mona Coder

SQL enables MySQL users to allocate a filed in Decimal format with specific Precision and Scale numbers as:

SQL 使 MySQL 用户能够将具有特定精度和比例数字的十进制格式的文件分配为:

CREATE TABLE test_table
(
    test_column DECIMAL(6,4) NOT NULL
);

How can I do this in phpMyAdmin as the field type has only length/value option available there?

我如何在 phpMyAdmin 中执行此操作,因为字段类型只有长度/值选项可用?

回答by unutbu

Decimals can be added to a MySQL database by using the DECIMAL(M,D)data type. This requires 2 arguments.

可以使用DECIMAL(M,D)数据类型将小数添加到 MySQL 数据库中。这需要 2 个参数。

  • M is the maximum number of digits, ranging from 1 to 65.
  • D is the number of decimal places available, ranging from 0 to 30.
  • M 是最大位数,范围从 1 到 65。
  • D 是可用的小数位数,范围从 0 到 30。

Note that with Ddigits reserved for decimal places, there can be at most M-Ddigits available for the integer part. So if we use DECIMAL(6,4), the number 45.8239would be valid, but 456.12would not.

请注意,对于D保留小数M-D位的数字,整数部分最多可以有数字。因此,如果我们使用DECIMAL(6,4),该数字45.8239将是有效的,但456.12不会。

To use this in phpMyAdmin, you can do the following:

要在 phpMyAdmin 中使用它,您可以执行以下操作:

In the Length/Valuefield type 6,4without the parentheses.

在没有括号的Length/Value字段类型6,4中。

enter image description here

在此处输入图片说明

results in a table structure like this:

结果是这样的表结构:

enter image description here

在此处输入图片说明