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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值