
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Trying to round a calculation to two decimal places in a new column with MySQL?
To round, use MySQL ROUND() function. Let us first create a table −
mysql> create table DemoTable1865 ( Value1 int, Value2 int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1865 values(40,60); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1865 values(100,400); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1865 values(545,896); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1865;
This will produce the following output −
+--------+--------+ | Value1 | Value2 | +--------+--------+ | 40 | 60 | | 100 | 400 | | 545 | 896 | +--------+--------+ 3 rows in set (0.00 sec)
Here is the query to round a calculation to 2 decimal places in a new column −
mysql> select round(Value1/Value2,2) as Result from DemoTable1865;
This will produce the following output −
+--------+ | Result | +--------+ | 0.67 | | 0.25 | | 0.61 | +--------+ 3 rows in set (0.00 sec)
- Related Articles
- How to round MySQL column with float values and display the result in a new column?
- How to round a number to n decimal places in Java
- Java Program to Round a Number to n Decimal Places
- Swift Program to Round a Number to n Decimal Places
- Haskell Program to Round a Number to n Decimal Places
- Kotlin Program to Round a Number to n Decimal Places
- C++ Program to Round a Number to n Decimal Places
- How to display a float with two decimal places in Python?
- Python - Round number of places after the decimal for column values in a Pandas DataFrame
- How to combine two tables and add a new column with records in MySQL?
- I want to round a number to 2 decimal places in SAPUI5. Could anyone help?
- How to parse float with two decimal places in JavaScript?
- Format amount values for thousands number with two decimal places in MySQL?
- How to round each value to two decimal places in columns if some columns are categorical in R data frame?
- How to round correlation values in the correlation matrix to zero decimal places in R?

Advertisements