- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to round MySQL column with float values and display the result in a new column?
Let us first create a table −
mysql> create table DemoTable ( Value float ); Query OK, 0 rows affected (0.95 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(12.4567); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(124.7884); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(45.64643); Query OK, 1 row affected (0.46 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------+ | Value | +---------+ | 12.4567 | | 124.788 | | 45.6464 | +---------+ 3 rows in set (0.00 sec)
Following is the query to round float records and display the result in a new column −
mysql> select Value,ROUND(Value,2) AS RoundValue from DemoTable;
This will produce the following output −
+---------+------------+ | Value | RoundValue | +---------+------------+ | 12.4567 | 12.46 | | 124.788 | 124.79 | | 45.6464 | 45.65 | +---------+------------+ 3 rows in set (0.00 sec)
Advertisements