MySQL十进制数据类型-用逗号截断插入值? [英] MySQL Decimal DataType - Truncating Insert Values With Commas?

查看:73
本文介绍了MySQL十进制数据类型-用逗号截断插入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类型为Decimal(12,2)的MySQL字段.使用以下查询获取插入内容时,我没有存储正确的值.

I have a MySQL field that is of the type Decimal(12,2). Upon using the following query to get an insert, I'm not getting the correct value stored.

INSERT INTO table (someValue) VALUES ('1,200');

这不是在小数字段"someValue"中显示"1200.00",而是显示"1.00"-在第一个逗号之后截断数据.

This, instead of displaying "1200.00" in the decimal field "someValue", is displaying "1.00" - truncating the data after the first comma.

我的问题是,为什么MySQL会出现这种现象,并且有一种简单的解决方法?

My questions are, why does MySQL have this behavior, and is there a simple way to get around it?

推荐答案

如果您的值是从某些HTML表单中读取的,并且您无法避免将逗号发送给查询,请执行以下操作:

if your value is read from some HTML form and you can't avoid the comma being sent to the query, do as follows:

INSERT INTO table (someValue) VALUES (replace('1,200',',','');

应该做的....

这篇关于MySQL十进制数据类型-用逗号截断插入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆