-- Round
-- Returns a numeric expression rounded to the specified length or precision.
--
-- Syntax
-- Round (numeric_expression, length [, function])
--
-- Parameter
-- Numeric_expression
--
-- Expression of exact or approximate numeric data type (except BIT data type ).
--
-- Length
--
-- The precision of numeric_expression to be rounded. The length must be tinyint, smallint, or Int. When length is a positive number, numeric_expression is rounded to the specified decimal place. When length is a negative number, numeric_expression is rounded to the left of the decimal point specified by length.
--
-- Function
--
-- Is the type of operation to be executed. The function must be tinyint, smallint, or Int. If the value of function or function is omitted is 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.
--
-- Return type
-- Returns the same type as numeric_expression.
--
-- Comment
-- Round always returns a value. If length is a negative number and it is greater than the number before the decimal point, round returns 0.
--
-- Example result
-- Round (748.58,-4) 0
--
-- When length is a negative number, no matter what data type, round returns a rounding numeric_expression.
--
-- Example result
-- Round (748.58,-1) 750.00
-- Round (748.58,-2) 700.00
-- Round (748.58,-3) 1000.00
--
-- Example
-- A. Use round and estimated values
-- The following example shows two expressions, indicating that the round function is used and the last number is always an estimate.
--
Select round (123.9994, 3), round (123.9995, 3)
Go
-- The following is the result set:
--
----------
-- 123.9990 124.0000
--
-- B. Use the approximate values of round and rounding
-- The following example shows rounding and approximate values.
--
-- Statement result
Select round (123.4545, 2)
-- 123.4500
Select round (123.45,-2)
-- 100.00
--
-- C. Use round to intercept
-- The following example uses two select statements to explain the difference between rounding and truncation. The first statement rounds the result. The second statement truncates the result.
--
-- Statement result
Select round (150.75, 0)
-- 151.00
Select round (150.75, 0, 1)
-- 150.00