ROUND

Description

The ROUND function is used to round numerical expressions to a specified number of decimal places. This function supports various input data types, including float, double, decimal, smallint, tinyint, int, and bigint.

Syntax Format

ROUND(expr [, d])

Parameter Description

  • expr: The numeric type expression that needs to be rounded.
  • d: An integer used to specify the number of decimal places to retain, supports negative values. The default value is 0.

Return Result

Returns the rounded numeric result, with the same type as the input expr.

Usage Example

  1. Retain one decimal place:
SELECT ROUND(3.14, 1); -- Result: 3.1
  1. Retain two decimal places:
SELECT ROUND(3.1415926, 2); -- Result: 3.14
  1. Retain the Integer Part:
SELECT ROUND(2.5); -- Result: 3
  1. Omit the decimal part:
SELECT ROUND(314.1592, -1); -- Result: 310
  1. Rounding negative numbers:
SELECT ROUND(-3.14, 1); -- Result: -3.1
  1. Round the decimal type:
SELECT ROUND(123.4567, 2); -- Result: 123.46