郑州知名做网站,莱芜最好的网站建设公司,网页版梦幻西游虎灯令,外贸网站找人建设FORMAT()函数 在mysql的查询中#xff0c;如果我们输入的是小数类型#xff0c;而保留几位小数因情况而变#xff0c;我们可以用FORMAT#xff08;#xff09;函数来设置想保留的几位小数。即将数据内容格式化#xff0c;将数据格式化为整数或者带几位小数的浮点数#…FORMAT()函数 在mysql的查询中如果我们输入的是小数类型而保留几位小数因情况而变我们可以用FORMAT函数来设置想保留的几位小数。即将数据内容格式化将数据格式化为整数或者带几位小数的浮点数四舍五入。
语法
SELECT FORMAT(a, b)
FROM table; 其中a为你要操作的字段b为保留几位小数
举例理解
sql语句
创建表
create table formathanshu(
price DOUBLE not null primary key,
name varchar(20) not null
)charsetutf8;
加入数据:
insert into formathanshu values(500.999,The Journey to the West);
insert into formathanshu values(4.6777,The Dream of Red Mansion);
insert into formathanshu values(99.999999,The Water margin);
insert into formathanshu values(33.3,Romance of the Three Kingdoms);
insert into formathanshu values(77.988,Border town);运行结果
要求
将price字段的所有数字保留两位小数 sql语句
SELECT name,FORMAT(price, 2) as 保留两位小数后的价格
FROM formathanshu; 运行结果 如果你想保留整数那么将后面的数字设为0就OK啦 https://blog.csdn.net/hanhanwanghaha宝藏女孩 欢迎您的关注 欢迎关注微信公众号宝藏女孩的成长日记 如有转载请注明出处如不注明盗者必究