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!

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!