
小数用double或者number不带精度作为存储,
示例如下,
1、创建测试表,create table test_num(id number, fee number(10,3))
2、插入测试数据,
insert into test_num values(1,0.8)
insert into test_num values(2,329.2)
insert into test_num values(4.44,15)
insert into test_num values(6,3)
commit
3、查询表中记录,select * from test_num,可以看到小数已经存入,
4、如果小数转整数,可以用trunc(直接去掉小数)或round(四舍五入)函数,
select t.*, trunc(fee) fee1, round(fee) fee2 from test_num t
数据库里面创建表是有小数点的是float类型。SQL Server 数据类型float(n): 从 -1.79E + 308 到 1.79E + 308 的浮动精度数字数据。 参数 n 指示该字段保存 4 字节还是 8 字节。float(24) 保存 4 字节,而 float(53) 保存 8 字节。n 的默认值是 53。
MySQL 数据类型FLOAT(size,d)带有浮动小数点的小数字。在括号中规定最大位数。在 d 参数中规定小数点右侧的最大位数。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)