
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Display 3 decimal places in MySQL?
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)
- Related Questions & Answers
- How to display a float with two decimal places in Python?
- How to display Y-axis labels with more decimal places in R?
- How to format number to 2 decimal places in MySQL?
- Select rows having more than 2 decimal places in MySQL?
- Format amount values for thousands number with two decimal places in MySQL?
- How to limit Decimal Places in Android EditText?
- How to get number located at 2 places before decimal point MySQL?
- How to display 3 random values from MySQL table?
- C++ Program to compute division upto n decimal places
- Trying to round a calculation to two decimal places in a new column with MySQL?
- How to parse float with two decimal places in JavaScript?
- MySQL limit in a range fail to display first 3 row?
- How to round a number to n decimal places in Java
- C# program to remove all the numbers after decimal places
- Java Program to Round a Number to n Decimal Places
Advertisements