Get the App
SLTechnology News&Howtos  ›  Database  › 

Rounding function and decimal in SQL

Shulou Source: shulou.com Published: 2022-06-01 14:10:01 10月03日 Update

Take the entire function:

1. Trunc (value,precision) intercepts a number by precision without rounding.

Returns the x value of the decimal place truncated to y: trunc (x, [y]):

Select trunc 23.33-23

2. Round (value,precision) enter the value [rounded off] according to the given precision (precision).

Returns the x value 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) [rounded up].

Returns the largest integer greater than or equal to x:

Select ceiling (23.33)-24

4. Floor (value), contrary to ceiling (), produces the smallest integer that is less than or equal to the specified value (value).

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 quantity of the value instead of its symbol, while sign (value) gives the symbol of the value instead of the quantity.

Returns the symbol of x:

Select sign (- 23.33)-1 Summary:

[rounding]: round ()

[round down]: FLOOR (), cast (x as int). The number of days of the date cannot be used with cast, and floor (cast (date as float)) is required.

[round up]: CEILING ()

[decimal]: x-floor (x)

Tags: Integer decimal symbol function maximum minimum rounding precision rounding right days decimal point numeric number date absolute value part input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux NVidia Docker Apple