Free tutorials & notes in Hindi & English · Clean code examples · Mobile friendly learning
MySQL + SQL · Lesson 61

MySQL Numeric Functions

Numeric Functions

Numeric functions transform one or more numeric expressions for calculation or display. They are scalar functions: normally one result is produced for each input row.

SELECT full_name, marks,
       ROUND(marks / 100 * 5, 2) AS score_out_of_5
FROM students
ORDER BY student_id;
Aarav | 86.50 | 4.33 Meera | 91.00 | 4.55 Kabir | 74.00 | 3.70 Sana | 88.50 | 4.43

ROUND, CEIL, FLOOR and TRUNCATE

SELECT ROUND(88.50, 0) AS rounded,
       CEIL(88.50) AS ceiling_value,
       FLOOR(88.50) AS floor_value,
       TRUNCATE(88.56, 1) AS truncated;
89 | 89 | 88 | 88.5

ROUND and TRUNCATE are different. Also test negative numbers: CEIL(-2.7) is -2, while FLOOR(-2.7) is -3.

ABS, MOD, POW and SQRT

SELECT ABS(-12.50) AS absolute_value,
       MOD(91, 10) AS remainder,
       POW(2, 5) AS power_value,
       SQRT(81) AS square_root;
12.50 | 1 | 32 | 9

Validate domains: SQRT of a negative real value returns NULL in MySQL, and division/modulo by zero must be handled according to SQL mode and warnings.

Numeric Functions in Reports

SELECT full_name,
       marks,
       CASE
         WHEN marks >= 90 THEN 'A1'
         WHEN marks >= 80 THEN 'A2'
         ELSE 'B or below'
       END AS grade,
       ROUND(marks, 0) AS display_marks
FROM students
ORDER BY marks DESC;

Keep raw values for calculations and round only the display unless official assessment rules require stored rounding.

Precision, NULL and Safe Calculations

  • Use DECIMAL for exact marks, fees and money.
  • FLOAT/DOUBLE are approximate.
  • Guard a denominator with NULLIF(denominator,0) when zero should produce NULL rather than invalid division.
  • Most functions propagate NULL.
  • Do not wrap indexed columns in functions inside WHERE without checking EXPLAIN and design alternatives.
SELECT obtained_marks / NULLIF(max_marks, 0) * 100
       AS percentage
FROM results;

Practice

  1. Round each mark to one decimal.
  2. Compare CEIL and FLOOR for -2.7.
  3. Find the remainder when 86 is divided by 5.
  4. Convert percentage to a five-point score.
  5. Write division protected by NULLIF.

Quick Summary

  • Rounding functions have different mathematical meanings.
  • ABS, MOD, POW and SQRT perform common calculations.
  • DECIMAL preserves exact fixed-point values.
  • Handle NULL, zero denominators, domains and index use deliberately.

Official References

References reviewed 14 August 2026.

Frequently Asked Questions

What is the difference between ROUND and TRUNCATE?
ROUND chooses the nearest value at the requested decimal place according to numeric rules. TRUNCATE removes later digits without rounding.
What is the difference between CEIL and FLOOR?
CEIL returns the smallest integer not less than the value; FLOOR returns the largest integer not greater than it. Negative values make the distinction clear.
What does MOD do?
MOD(a,b) returns the remainder of a divided by b. The % operator is also available in MySQL.
Why should money use DECIMAL?
DECIMAL stores exact fixed-point values. FLOAT/DOUBLE are approximate and can produce representation or rounding surprises.
What happens when a numeric function receives NULL?
Most numeric functions return NULL. Decide whether to preserve missingness or provide a semantically valid fallback.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.