To display 3 digits after decimal, use TRUNCATE(). Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value DECIMAL(10,5) ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Value) values(109.4567); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(Value) values(15.9875); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(Value) values(1234.2346789); Query OK, 1 row affected, 1 warning (0.14 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+------------+ | Id | Value | +----+------------+ | 1 | 109.45670 | | 2 | 15.98750 | | 3 | 1234.23468 | +----+------------+ 3 rows in set (0.00 sec)
Here is the query to display 3 digits after decimal i.e. 3 decimal places −
mysql> select truncate(Value,3) from DemoTable;
This will produce the following output −
+-------------------+ | truncate(Value,3) | +-------------------+ | 109.456 | | 15.987 | | 1234.234 | +-------------------+ 3 rows in set (0.00 sec)