Mathematical Functions
914
As of MySQL 5.0.3,
ROUND()
[913]
uses the following rules depending on the type of the first
argument:
• For exact-value numbers,
ROUND()
[913]
uses the “round half away from zero” or “round toward
nearest” rule: A value with a fractional part of .5 or greater is rounded up to the next integer if
positive or down to the next integer if negative. (In other words, it is rounded away from zero.) A
value with a fractional part less than .5 is rounded down to the next integer if positive or up to the
next integer if negative.
• For approximate-value numbers, the result depends on the C library. On many systems, this
means that
ROUND()
[913]
uses the "round to nearest even" rule: A value with any fractional part
is rounded to the nearest even integer.
The following example shows how rounding differs for exact and approximate values:
mysql>
SELECT ROUND(2.5), ROUND(25E-1);
+------------+--------------+
| ROUND(2.5) | ROUND(25E-1) |
+------------+--------------+
| 3 | 2 |
+------------+--------------+
For more information, see
Section 12.17, “Precision Math”
.
•
SIGN(X)
[914]
Returns the sign of the argument as
-1
,
0
, or
1
, depending on whether
X
is negative, zero, or
positive.
mysql>
SELECT SIGN(-32);
-> -1
mysql>
SELECT SIGN(0);
-> 0
mysql>
SELECT SIGN(234);
-> 1
•
SIN(X)
[914]
Returns the sine of
X
, where
X
is given in radians.
mysql>
SELECT SIN(PI());
-> 1.2246063538224e-16
mysql>
SELECT ROUND(SIN(PI()));
-> 0
•
SQRT(X)
[914]
Returns the square root of a nonnegative number
X
.
mysql>
SELECT SQRT(4);
-> 2
mysql>
SELECT SQRT(20);
-> 4.4721359549996
mysql>
SELECT SQRT(-16);
-> NULL
•
TAN(X)
[914]
Returns the tangent of
X
, where
X
is given in radians.
mysql>
SELECT TAN(PI());
-> -1.2246063538224e-16
mysql>
SELECT TAN(PI()+1);
-> 1.5574077246549
•
TRUNCATE(X,D)
[914]
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...