MySQL DECIMAL类型

mysql> use test;
Database changed

mysql> create table teacher(score decimal(6, 2));
Query OK, 0 rows affected (0.04 sec)

mysql> insert into teacher values(34.35464), (23534523.45434), ('3223.3557');
Query OK, 3 rows affected, 3 warnings (0.04 sec)
Records: 3  Duplicates: 0  Warnings: 3

mysql> select * from teacher;
+---------+
| score   |
+---------+
|   34.35 |
| 9999.99 |
| 3223.36 |
+---------+
3 rows in set (0.00 sec)

# decimal存储负数
mysql> insert into teacher values(-4508.90764); Query OK, 1 row affected, 1 warning (0.08 sec) mysql> select * from teacher; +----------+ | score | +----------+ | 34.35 | | 9999.99 | | 3223.36 | | -4508.91 | +----------+ 4 rows in set (0.00 sec) mysql>

 

# decimal中以字符串存储'7956.54768'


mysql> insert into teacher values('7956.54768'); Query OK, 1 row affected, 1 warning (0.04 sec) mysql> select * from teacher; +----------+ | score | +----------+ | 34.35 | | 9999.99 | | 3223.36 | | -4508.91 | | 7956.55 | +----------+ 5 rows in set (0.00 sec) mysql>

(1)DECIMAL 类型不同于FLOAT和DOUBLE,其中DECIMAL 实际是以串存放的。

(2)DECIMAL(6, 2) 能够表示从-9999.99 到9999.99 的所有值,而且存储符号和小数点。

你可能感兴趣的:(mysql)