Summary:
Use round SQL functions to round-up numeric data, as described below
Lab environment: SQL Server 2008
Transferred from: http://www.maomao365.com/?p=6454
Recently received the user needs, to the numerical data, no matter how much behind the data, the direct rounding operation, wrestling, finally found that the round function can satisfy this operation.
--------------------------------------------------
The Round Function rounding feature describes:
Round Syntax Introduction:
Round (data expression, length [, Operation mode])
----------------------
Parameter description:
Data expression:
Receive a tinyint, int, bigint, decimal, numeric, money, smallmoney, float, real
Length:
This parameter must be of type tinyint int smallint
The precision of round function rounding
Operation mode:
This parameter must be of type tinyint int smallint
Default value: 0, if you enter a different value, the data expression will be truncated
----------------------
Return Value Description:
tinyint return int
int returns int
bigint return bigint
Decimal Numberic Returns decimal Numberic
Money smallmoney return Money
Float Real returns to float
-----------------------
<span style= "color:red;" >
Precautions:
When "Length" is positive, the number of digits rounded after the decimal point
When "Length" is negative, the number of digits rounded before the decimal point
</span>
-----------------------------------------------------
Round Application Examples:
SELECT ROUND(8989.3652,2),--2 bits left after the decimal place, roundedROUND(8989.3652,-2),--Round 2 bits before the decimal place, rounded---Rounding of all decimal digits roundedROUND(8956.34,0),ROUND(8956.65,0),ROUND(8956.25,0), ---truncate data after rounding position of dataROUND(16081.83,0,-2),ROUND(16081.83,0,1),ROUND(16081.83,0,5),ROUND(16081.835,2,8),ROUND(16081.836,-2,6),ROUND(16081.83,-2,7)Go---Example: SQL Cancellation rounding method sharing---lost two bits after decimal place, do not take rounding operationsSelect round(8989.999,2,9)
MSSQL SQL Server method sharing for canceling numeric rounding