An instance of an up-down, rounded-down, rounding-up in SQL Server!

Source: Internet
Author: User

http://blog.csdn.net/dxnn520/article/details/8454132

==================================================== "Rounding to take the whole intercept"

Select Round (54.56,0)

==================================================== "Take down the whole intercept"

SELECT Floor (54.56)

==================================================== "Take up the whole intercept"

SELECT CEILING (13.15)

The following transfers are from: http://www.2cto.com/database/201209/156996.html

--mssql the use of the integer function


--Divide two integers to truncate fractional parts
Select 3/4,4/3,5/3
--Results 0,1,1

--Returns the smallest integer greater than or equal to the given number expression
SELECT CEILING (123.55), CEILING (123.45), CEILING ( -123.45), CEILING (0.0)
--Results 124,124,-123,0
--Www.2cto.com
--Rounding round (A, A, b)--result A is accurate to the right of the decimal point, or to the left B bit
Select Round (54.36,-2), round (54.36,-1), round (54.36,0), round (54.36,1), round (54.36,2)
--Results 100.00,50.00,54.00,54.40,54.36

---rounded and converted to integers
Select CAST (Round (56.361,0) as int), CAST (round (56.561,0) as int)
--Results 56,57

--Using For example

---two integers to divide the fractional part (all forward bits)
DECLARE @dividend decimal (20,2), @divisor decimal (20,2)

Set @dividend =3
Set @divisor =4
Select CEILING (@dividend/@divisor)
--Results 1

Set @dividend =4
Set @divisor =3
Select CEILING (@dividend/@divisor)
--Results 2

Set @dividend =5
Set @divisor =3
Select CEILING (@dividend/@divisor)
--Results 2


---two integers rounded up to an integer
Set @dividend =3
Set @divisor =4
Select CAST (Round (@dividend/@divisor, 0) as int)
--Results 1

Set @dividend =4
Set @divisor =3
Select CAST (Round (@dividend/@divisor, 0) as int)
--Results 1

Set @dividend =5
Set @divisor =3
Select CAST (Round (@dividend/@divisor, 0) as int)

--Results 2

==================================================== "Rounding to take the whole intercept"

Select Round (54.56,0)

==================================================== "Take down the whole intercept"

SELECT Floor (54.56)

==================================================== "Take up the whole intercept"

SELECT CEILING (13.15)

An instance of an up-down, rounded-down, rounding-up in SQL Server!

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.