
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Change Value of Decimal 19,2 When Inserting into 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)
Advertisements