问题
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