Numeric Types
836
0 to 23 results in a 4-byte single-precision
FLOAT
column. A precision from 24 to 53 results in an 8-byte
double-precision
DOUBLE
column.
MySQL permits a nonstandard syntax:
FLOAT(M,D)
or
REAL(M,D)
or
DOUBLE PRECISION(M,D)
.
Here, “
(M,D)
” means than values can be stored with up to
M
digits in total, of which
D
digits may be
after the decimal point. For example, a column defined as
FLOAT(7,4)
will look like
-999.9999
when displayed. MySQL performs rounding when storing values, so if you insert
999.00009
into a
FLOAT(7,4)
column, the approximate result is
999.0001
.
Because floating-point values are approximate and not stored as exact values, attempts to treat them
as exact in comparisons may lead to problems. They are also subject to platform or implementation
dependencies. For more information, see
Section C.5.5.8, “Problems with Floating-Point Values”
For maximum portability, code requiring storage of approximate numeric data values should use
FLOAT
or
DOUBLE PRECISION
with no specification of precision or number of digits.
11.1.4.4. Bit-Value Type -
BIT
As of MySQL 5.0.3, the
BIT
data type is used to store bit-field values. A type of
BIT(M)
enables
storage of
M
-bit values.
M
can range from 1 to 64.
To specify bit values,
b'value'
notation can be used.
value
is a binary value written using zeros and
ones. For example,
b'111'
and
b'10000000'
represent 7 and 128, respectively. See
Section 9.1.6,
“Bit-Field Literals”
.
If you assign a value to a
BIT(M)
column that is less than
M
bits long, the value is padded on the left
with zeros. For example, assigning a value of
b'101'
to a
BIT(6)
column is, in effect, the same as
assigning
b'000101'
.
11.1.4.5. Numeric Type Attributes
MySQL supports an extension for optionally specifying the display width of integer data types in
parentheses following the base keyword for the type. For example,
INT(4)
specifies an
INT
with a
display width of four digits. This optional display width may be used by applications to display integer
values having a width less than the width specified for the column by left-padding them with spaces.
(That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to
the application.)
The display width does not constrain the range of values that can be stored in the column. Nor does
it prevent values wider than the column display width from being displayed correctly. For example, a
column specified as
SMALLINT(3)
has the usual
SMALLINT
range of
-32768
to
32767
, and values
outside the range permitted by three digits are displayed in full using more than three digits.
When used in conjunction with the optional (nonstandard) attribute
ZEROFILL
, the default padding of
spaces is replaced with zeros. For example, for a column declared as
INT(4) ZEROFILL
, a value of
5
is retrieved as
0005
.
Note
The
ZEROFILL
attribute is ignored when a column is involved in expressions or
UNION
queries.
If you store values larger than the display width in an integer column that has
the
ZEROFILL
attribute, you may experience problems when MySQL generates
temporary tables for some complicated joins. In these cases, MySQL assumes
that the data values fit within the column display width.
All integer types can have an optional (nonstandard) attribute
UNSIGNED
. Unsigned type can be used
to permit only nonnegative numbers in a column or when you need a larger upper numeric range for
the column. For example, if an
INT
column is
UNSIGNED
, the size of the column's range is the same
but its endpoints shift from
-2147483648
and
2147483647
up to
0
and
4294967295
.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...