ROUND()

SQL · Math Functions

Theory

ROUND rounds a number to a chosen number of decimal places. ROUND(3.14159, 2) gives 3.14, ROUND(2.5) gives 3, and ROUND(salary / 12.0, 2) gives a monthly salary in rupees and paise. If you leave out the second argument it rounds to a whole number. Most databases also accept a negative second argument to round to tens, hundreds or thousands, such as ROUND(48750, -3) = 49000, but SQLite does not support that.

Two details matter in practice. First, integer division: in SQLite, PostgreSQL and SQL Server, 50000 / 12 is integer division and gives 4166 before ROUND even runs, so write 12.0 to keep the decimals. Second, decimal numbers stored as floating point are not always exact, so a value that looks like 2.675 may really be 2.67499999 and round down. Use DECIMAL/NUMERIC types for money, and round only in the final output.

Why we use it

Raw calculations produce long decimals (41666.666666...) that are hard to read and look wrong on invoices or dashboards. ROUND presents numbers at a sensible precision such as two decimals for currency.

When to use it

Use ROUND in the final SELECT for display and reporting. Avoid rounding in intermediate steps, because errors add up. Use CEIL or FLOOR when you always need to round in one direction, not to the nearest value.

How it works

  1. Number and number of decimals, e.g. (41666.667, 2)
  2. Integer / integer division? Yes: Use 12.0 so decimals are kept. No: Continue.
  3. Look at the digit after the last kept place
  4. Is that digit 5 or more? Yes: Round the kept part up. No: Round the kept part down.
  5. Return the rounded number

Syntax

ROUND(number, decimals)

Example

SELECT ROUND(salary / 12.0, 2) FROM employees;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic