MySQL选择格式,圆列 [英] MySql select format, round column

查看:45
本文介绍了MySQL选择格式,圆列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中的产品具有以下列:price [小数8,5]和小数[tinyint-最大值为5]. 当我列出产品时,必须根据小数列中指定的小数显示价格. 我尝试过这样的事情(使用mysql)

I have a table with products that have columns like this: price[decimals 8,5] and decimals [tinyint - max value is 5]. When I list products must show price according to the decimals specified in decimals column. I tried something like this(with mysql)

select p.price, round(p.price, p.decimals) as price, p.decimals
from product p

但返回

100.35667   100.35700   3

,我想成为100. 我还看到,"Round"将数字四舍五入,这不是我的范围. 问候.

and i would like to be 100. I also see that 'Round' rounds the number which is not my scope. Regards.

推荐答案

您需要FORMAT函数:

http://dev.mysql.com/doc/refman/5.0/zh-CN/string-functions.html#function_format

SELECT 
    P.price, 
    FORMAT(P.price, P.decimals) as price, 
    P.decimals
FROM 
    product P;

这篇关于MySQL选择格式,圆列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆