如何在MySQL的DECIMAL类型字段中插入浮点数?

时间:2022-02-27 16:30:48

I have the field field_name with the following type DECIMAL (10, 2). I want to insert a floating-point number in this field. I have the following SQL-query:

我有字段field_name与以下类型DECIMAL(10,2)。我想在此字段中插入一个浮点数。我有以下SQL查询:

UPDATE `table_name` SET `field_name` = "0,20" WHERE `primary_key` = 1;

SELECT `field_name` FROM `table_name` WHERE `primary_key` = 1;

>> 0.00

How do I write a floating-point number?

如何编写浮点数?

3 个解决方案

#1


2  

Use a decimal point . instead of a comma ,:

使用小数点。而不是逗号,:

UPDATE table_name SET field_name = 0.20 WHERE primary_key = 1

However, do note that the DECIMAL type is fixed-point, not floating-point.

但请注意,DECIMAL类型是定点的,而不是浮点型。

#2


1  

Try this:

尝试这个:

UPDATE `table_name` SET `field_name` = 0.20 WHERE `primary_key` = 1;

#3


0  

UPDATE `table_name` 
SET `field_name` = 0.20 
WHERE `primary_key` = 1;

It is called floating-point-number - so use a point instead of comma. And since it is no string you don't need the quotes around it.

它被称为浮点数 - 所以使用一个点而不是逗号。因为它不是字符串,所以你不需要它周围的引号。

#1


2  

Use a decimal point . instead of a comma ,:

使用小数点。而不是逗号,:

UPDATE table_name SET field_name = 0.20 WHERE primary_key = 1

However, do note that the DECIMAL type is fixed-point, not floating-point.

但请注意,DECIMAL类型是定点的,而不是浮点型。

#2


1  

Try this:

尝试这个:

UPDATE `table_name` SET `field_name` = 0.20 WHERE `primary_key` = 1;

#3


0  

UPDATE `table_name` 
SET `field_name` = 0.20 
WHERE `primary_key` = 1;

It is called floating-point-number - so use a point instead of comma. And since it is no string you don't need the quotes around it.

它被称为浮点数 - 所以使用一个点而不是逗号。因为它不是字符串,所以你不需要它周围的引号。