MySQL Decimal DataType - Truncating Insert Values With Commas?

前提是你 提交于 2020-01-11 13:49:11

问题


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');

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

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


回答1:


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',',','');

that should do....



来源:https://stackoverflow.com/questions/28840994/mysql-decimal-datatype-truncating-insert-values-with-commas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!