Rounding

Beginner

In SQL, rounding functions are used to manipulate numeric values by adjusting them to a specific precision or to the nearest whole number. Here are some common rounding functions:

  1. ROUND:

    • The ROUND function is used to round a numeric value to a specified number of decimal places.
    • Syntax: ROUND(numeric_expression, length [, function])
    • Example: SELECT ROUND(123.456, 2); returns 123.46
  2. FLOOR:

    • The FLOOR function rounds a numeric value down to the nearest integer less than or equal to the original value.
    • Syntax: FLOOR(numeric_expression)
    • Example: SELECT FLOOR(123.456); returns 123
  3. CEIL:

    • The CEIL function rounds a numeric value up to the nearest integer greater than or equal to the original value. It’s short for “ceiling”.
    • Syntax: CEIL(numeric_expression)
    • Example: SELECT CEIL(123.456); returns 124
  4. TRUNCATE:

    • The TRUNCATE function truncates a numeric value to a specified number of decimal places, effectively removing the decimal part.
    • Syntax: TRUNCATE(numeric_expression, length)
    • Example: SELECT TRUNCATE(123.456, 2); returns 123.45