MySQL change value of decimal(19, 2) when insert into database

Rasool Ghafari :

I created table as you can see below:

create table sample_tbl
(
    decimal_column decimal(19,2) null
);

now, when i insert into this table with simple insert command:

insert into sample_tbl values (18.939);

MySQL stores it as 18.94, how should i fix this problem? i want to store real value: 18.93

forpas :

The value that you insert is rounded correctly to 18.94.
What you want is to truncate the value to 2 decimal places, so use the function truncate():

insert into sample_tbl values (truncate(18.939, 2));

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=401512&siteId=1