mysql--(入门语句6--浮点列)

//浮点列

float(M,D)
declimal(M,D)

M:精度(总位数,不包括点)
D:标度(小数位)

price (6,2)  9999.99 ,-9999.99

//创建一个商品表
create table goods(
name varchar(10) not null default '',
price float(6,2) not null default 0.00
)charset utf8;

desc goods;

insert into goods
(name,price)
values
('跑步机','688.789');


发现会四舍五入,不是数学里的那种,是银行里的那种。

1379的时候,5舍

2468的时候,5进

//定点型

alter table goods
add
bigprice float(9,2) not null default 0.0
;


alter table goods
add
deprice decimal (9,2) not null default 0.0
;

desc goods;//查看表结构


下面就是对float和decimal进行对比:

浮点型的值就出错了,但是定点型就很好的保持了精度:

//新增一个商品,自行车
insert into goods
(name,bigprice,deprice)
values
('自行车',1234567.23,1234567.23);


float(4,2) unsigned   0.00-99.99



猜你喜欢

转载自blog.csdn.net/qq_32823673/article/details/80410238