Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
From calculating sales commissions and compound interest to processing GPS Euclidean distances and statistical distributions, SQL provides a comprehensive suite of mathematical functions. In this tutorial, you will master the most common scalar mathematical operations in MySQL.
ROUND() vs TRUNCATE()The two most common methods for reducing decimal precision are rounding and truncation:
ROUND(number, [decimals])Rounds a number according to standard mathematical rounding rules (0.5 and above rounds up, below rounds down):
TRUNCATE(number, decimals)Cuts off decimal places immediately without rounding:
CEIL() and FLOOR()CEIL() / CEILING(): Rounds a decimal up to the nearest integer.FLOOR(): Rounds a decimal down to the nearest integer.ABS(number)Returns the non-negative absolute magnitude of a number:
MOD(N, M) or N % M (Remainder)Returns the remainder of dividing N by M:
100 / 0) returns NULL with a warning, rather than crashing the query. To handle potential zeros gracefully, use NULLIF:ROUND() on a FLOAT column can yield unexpected tiny fractional tails. Always cast or store monetary calculations in DECIMAL.SELECT ROUND(84.346, 2);?TRUNCATE(84.346, 2) differ from ROUND(84.346, 2)?SELECT 50 / 0;) in MySQL?SELECT MOD(25, 4); return?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| SQL String Functions | Date & Time Functions |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.