MySQL Numeric Functions


1. ROUND() - Rounds a Number

Rounds a number to the nearest integer or to a specified number of decimal places.

Syntax:

ROUND(number, decimal_places)

Example:

SELECT ROUND(12.567, 2); -- Rounds to 2 decimal places
SELECT ROUND(12.567); -- Rounds to nearest integer
SELECT ROUND(125.67, -1); -- Rounds to nearest 10

Output:

12.57
13
130

2. TRUNCATE() - Truncates a Number

Cuts off a number to a specified number of decimal places without rounding.

Syntax:

TRUNCATE(number, decimal_places)

Example:

SELECT TRUNCATE(12.567, 2); -- Cuts off after 2 decimal places