Oracle 5.0 Reference Manual page 1027

Table of Contents

Advertisement

| 1.0000 | 0.99999999999991 |
+--------+------------------+
Example 2. Multiplication is performed with the scale required by standard SQL. That is, for two
numbers
and
that have scale
X1
X2
Before MySQL 5.0.3, this is what happens:
mysql>
SELECT .01 * .01;
+-----------+
| .01 * .01 |
+-----------+
|
0.00 |
+-----------+
The displayed value is incorrect. The value was calculated correctly in this case, but not displayed to
the required scale. To see that the calculated value actually was .0001, try this:
mysql>
SELECT .01 * .01 + .0000;
+-------------------+
| .01 * .01 + .0000 |
+-------------------+
|
0.0001 |
+-------------------+
As of MySQL 5.0.3, the displayed scale is correct:
mysql>
SELECT .01 * .01;
+-----------+
| .01 * .01 |
+-----------+
| 0.0001
|
+-----------+
Example 3. Rounding behavior for exact-value numbers is well-defined.
Before MySQL 5.0.3, rounding behavior (for example, with the
on the implementation of the underlying C library. This results in inconsistencies from platform to
platform. For example, you might get a different value on Windows than on Linux, or a different value
on x86 machines than on PowerPC machines.
As of MySQL 5.0.3, rounding happens like this:
• Rounding for exact-value columns
"round half away from zero" rule. Values with a fractional part of .5 or greater are rounded away from
zero to the nearest integer, as shown here:
mysql>
SELECT ROUND(2.5), ROUND(-2.5);
+------------+-------------+
| ROUND(2.5) | ROUND(-2.5) |
+------------+-------------+
| 3
| -3
+------------+-------------+
• Rounding for floating-point values uses the C library, which on many systems uses the "round to
nearest even" rule. Values with any fractional part on such systems are rounded to the nearest even
integer:
mysql>
SELECT ROUND(2.5E0), ROUND(-2.5E0);
+--------------+---------------+
| ROUND(2.5E0) | ROUND(-2.5E0) |
+--------------+---------------+
|
2 |
+--------------+---------------+
Example 4. In strict mode, inserting a value that is out of range for a column causes an error, rather
than truncation to a legal value.
Precision Math Examples
and S2, the scale of the result is
S1
(DECIMAL
and integer) and exact-valued numbers uses the
|
-2 |
1007
S1 +
S2:
[913]
function) is dependent
ROUND()

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents