Change value of decimal(19, 2) when inserting into the database in MySQL?



To store the exact real value, you need to use truncate() with 2 decimal point. Let us create a table −

Following is the query to create a table.

mysql> create table demo59 −> ( −> price decimal(19,2) −> ); Query OK, 0 rows affected (1.12 sec)

Insert some records into the table with the help of insert command −

mysql> insert into demo59 values(truncate(15.346, 2)); Query OK, 1 row affected (0.14 sec) mysql> insert into demo59 values(truncate(20.379, 2)); Query OK, 1 row affected (0.72 sec) mysql> insert into demo59 values(truncate(25.555, 2)); Query OK, 1 row affected (0.16 sec) mysql> insert into demo59 values(truncate(100.456, 2)); Query OK, 1 row affected (0.21 sec)

Display records from the table using select statement −

mysql> select *from demo59;

This will produce the following output −

+--------+ | price | +--------+ | 15.34 | | 20.37 | | 25.55 | | 100.45 | +--------+ 4 rows in set (0.00 sec)
Updated on: 2020-11-20T07:10:41+05:30

216 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements