Class 27 of 58 • Operators, Patterns & Functions

SQL Math & Numeric Functions: Rounding, Arithmetic & Precision

Database systems are frequently called upon to perform financial auditing, scientific computations, statistical modeling, and percentage calculations. SQL provides built-in Numeric & Math Functions that operate efficiently on integer, float, and decimal data types.


Core SQL Math Functions Reference

Function & Syntax Operation Performed Example & Output
ROUND(x, [d]) Rounds number x to d decimal places (default is 0). ROUND(3.856, 2) → 3.86
CEIL(x) / CEILING(x) Rounds number UP to the nearest whole integer. CEIL(4.01) → 5
FLOOR(x) Rounds number DOWN to the nearest whole integer. FLOOR(4.99) → 4
ABS(x) Returns the absolute (non-negative) magnitude. ABS(-25.50) → 25.50
MOD(n, d) Returns the integer remainder of division (n % d). MOD(10, 3) → 1
POWER(x, y) Computes base x raised to exponent y. POWER(2, 8) → 256
SQRT(x) Returns square root of a non-negative number. SQRT(81) → 9

Hands-on Query: Calculating Payroll Deductions

-- Compute tax, provident fund, and rounded net salary
SELECT 
    emp_name,
    salary,
    ROUND(salary * 0.12, 2) AS pf_deduction,
    ROUND(salary * 0.10, 2) AS income_tax,
    FLOOR(salary - (salary * 0.22)) AS net_take_home
FROM employees;

Next, let us master calendar calculations using SQL Date & Time Functions!


Frequently Asked Questions (FAQ)

ROUND(x, d) rounds x to d decimal places using standard half-up rounding. CEIL(x) rounds UP to the nearest integer. FLOOR(x) rounds DOWN to the nearest integer.

MOD(n, d) or n % d returns the remainder of dividing n by d (e.g., MOD(17, 5) returns 2). It is frequently used to identify odd/even rows.

ABS(x) returns the absolute positive value of a number (e.g., ABS(-45.8) returns 45.8).

Next Step in Your SQL Database Learning Path:

Proceed to the next class in sequence to build production mastery of relational database architecture.

Continue to Class 28: Date & Time Functions → Previous: ← String Functions | Full Syllabus


Related SQL Masterclass Lessons & Recommended Next Topics

Aggregate Functions →

Combining math functions with SUM, AVG, and STDDEV.

String Functions →

Formatting numbers as currency strings and decimals.

Numeric Data Types →

DECIMAL vs FLOAT vs INT precision and rounding nuances.

Date Math Functions →

Calculating day intervals, durations, and timestamps.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!