MSSQL SQL Server method sharing for canceling numeric rounding

Source: Internet
Author: User
Tags mssql


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.