Rounding functions in SQL, taking decimals

Source: Internet
Author: User
Tags abs

Take the whole function:

1. Trunc (value,precision) intercepts a number by precision (precision) and does not perform rounding operations.
Returns the X value of the truncated to Y decimal places: Trunc (X,[y]):

select trunc(23.33) ------------23

2, round (value,precision) input the value [rounding rounding] according to the given precision (precision).
Returns the x value of the Y-bit rounded to the right of the decimal point: Round (X,[y]):

select round(23.33) ------------23

3, ceiling (value) produces the smallest integer greater than or equal to the specified value (value) [Rounding up].
Returns the largest integer greater than or equal to x:

select ceiling(23.33) -----------24

4. Floor (value), in contrast to ceiling (), produces the smallest integer that is less than or equal to the specified value (value) [rounded down].
Returns the largest integer equal to or less than x:

select floor(23.33) ------------23

5. Sign (value) is opposite to the absolute value function abs (). ABS () gives the amount of the value rather than its symbol, and sign (value) gives the value a symbol rather than a quantity.
Returns the symbol for x:

select sign(-23.33) -------------1
Summarize:

Round rounding: Round ()
"Rounding Down": Floor (), cast (x as int). Cast, Floor (cast (date as float) should not be used for the days of the pick date
"Rounding Up": CEILING ()
"Take Decimal": X-floor (x)

Rounding functions in SQL, taking decimals

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.