您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

注意mysql 中一订要用decimal标识货币的值

2025/6/2 11:54:21发布15次查看
注意mysql 中一定要用decimal标识货币的值 注意mysql 中一定要用decimal标识货币的值!不要用float了,举例说明: create table ledgerentries ( ledgerentryid int primary key auto_increment not null ,customerid int not null ,amount float not null );
注意mysql 中一定要用decimal标识货币的值
注意mysql 中一定要用decimal标识货币的值!不要用float了,举例说明:
create table ledgerentries
(
ledgerentryid int primary key auto_increment not null
,customerid int not null
,amount float not null
);
然后插入一些数据;
insert into ledgerentries (customerid, amount)
values (1, 3.14);
insert into ledgerentries (customerid, amount)
values (1, 30000.14);
最后查询下
select * from ledgerentries;
+---------------+------------+---------+
| ledgerentryid | customerid | amount  |
+---------------+------------+---------+
|             1 |          1 |    3.14 |
|             2 |          1 | 30000.1 |
+---------------+------------+---------+
看到了么?没了最后的一位!,因此,赶紧用decimal吧
create table ledgerentries
(
ledgerentryid int primary key auto_increment not null
,customerid int not null
,amount decimal(10,2) not null
);
insert into ledgerentries (customerid, amount)
values (1, 3.14);
-- this is the largest value we can insert into a decimal(10,2)
-- if we have two numbers to the right of the decimal point
insert into ledgerentries (customerid, amount)
values (1, 99999999.99);
select * from ledgerentries;
+---------------+------------+-------------+
| ledgerentryid | customerid | amount      |
+---------------+------------+-------------+
|             1 |          1 |        3.14 |
|             2 |          1 | 99999999.99 |
+---------------+------------+-------------+
2 rows in set (0.00 sec)
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product