MySQL 如何在mysql中正确定义[float]数据类型

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

How to properly define the [float] data type in mysql

mysqlsqlfloating-point

提问by Itay Moav -Malimovka

I defined (through PHPMYADMIN) a field with the floatdata type.
When I try to insert a number as 78.556677099932222377 it will translate it to 79.
How do I make it to save the correct number, at least 7 places after the decimal dot?

我(通过 PHPMYADMIN)定义了一个具有float数据类型的字段。
当我尝试插入一个数字 78.556677099932222377 时,它会将其转换为 79。
如何保存正确的数字,小数点后至少 7 位?

回答by Stefan Khan-Kernahan

How do you define the float in phpMyAdmin

你如何在phpMyAdmin中定义浮动

FLOAT(23,19)

when u declare the field you could use that above.

当您声明该字段时,您可以在上面使用它。

Better to go with Cygnusx1 and change to decimal

最好使用 Cygnusx1 并更改为十进制

see MySQL numeric types

请参阅MySQL 数字类型

and also Problems with Float

还有浮动的问题

回答by Amranur Rahman

Open phpMyAdmin with structure option and define the float as:

使用结构选项打开 phpMyAdmin 并将浮点数定义为:

FLOAT(23,19)

clear in this picture: enter image description here

在这张图片中清楚: 在此处输入图片说明

回答by Cygnusx1

DECIMAL is what you looking for.

DECIMAL 正是您要找的。

ref:

参考:

SQL Decimal is used to specify the values in decimal datatype. The Decimal datatype can be of two types : Decimal (p) refers to floating point and Decimal fixed point (p,s). The DECIMAL data type can store decimal floating-point numbers up to a maximum of 32 significant digits and Decimal fixed point can store upto 16 significant digits.

SQL Decimal 用于指定十进制数据类型中的值。Decimal 数据类型可以有两种类型:Decimal (p) 指的是浮点数和 Decimal 定点数 (p,s)。DECIMAL 数据类型可以存储最多 32 位有效数字的十进制浮点数,而 Decimal 定点数可以存储最多 16 位有效数字。