
- 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
Round records with numbers in MySQL
To round number, use MySQL ROUND(). Let us first create a table −
mysql> create table DemoTable -> ( -> Amount DECIMAL(10,4) -> ); Query OK, 0 rows affected (1.18 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100.578); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1000.458); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(980.89); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output−
+-----------+ | Amount | +-----------+ | 100.5780 | | 1000.4580 | | 980.8900 | +-----------+ 3 rows in set (0.00 sec)
Here is the query for rounding numbers −
mysql> update DemoTable set Amount=round(Amount); Query OK, 3 rows affected (0.12 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable;
This will produce the following output−
+-----------+ | Amount | +-----------+ | 101.0000 | | 1000.0000 | | 981.0000 | +-----------+ 3 rows in set (0.00 sec)
- Related Articles
- Order VARCHAR records with string and numbers in MySQL
- How to select records beginning with certain numbers in MySQL?
- Implement MySQL REGEXP to fetch records with . and numbers
- How to update records in a column with random numbers in MySQL?
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- MySQL regexp to display only records with strings or strings mixed with numbers. Ignore only the number records
- How to ignore specific records and add remaining corresponding records (numbers) in MySQL?
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- Select records with ACTIVE status in MySQL set with ENUM
- Round float and double numbers in Java
- How to round exponential numbers in R?
- How to round the numbers in TypeScript?
- Display records with more than two occurrences in MySQL?
- Find records with double quotes in a MySQL column?
- How to insert records with double quotes in MySQL?

Advertisements