MySQL:将小数转换为视图内的百分比 [英] MySQL: turn decimal into percent within view

查看:1276
本文介绍了MySQL:将小数转换为视图内的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经继承了一个数据库,并且正在使用MySQL中的视图从数据库中返回特定信息.我有些麻烦,将返回的十进制数值转换为百分比.

I've inherited a database and am using views in MySQL to return specific information from a database. I'm having a little trouble one portion- turning the returned numeric value that is a decimal into a percentage.

我不想在php中执行此操作-我专门尝试首先格式化视图中的所有内容.我意识到这不一定是每个人都这样做的方式,但是对于我的具体情况,这是最佳的整体解决方案.

I don't want to do this in the php- I am specifically trying to format everything in the view first. I realize this is not necessarily the way everyone does this, but for my specific situation it is the best overall solution.

数据库中的示例值:0.46

The example value in the database: 0.46

我希望退货:46%

当前查询的相关部分:

    SELECT CONCAT(a.fa_rate, '%') as rate_percent
    FROM accounts a;

这将返回0.46%.是否可以在不将数字转换为字符串的情况下返回我想要的结果?当前数据类型为浮点型.

This returns 0.46%. Is it possible to return the result I want to have without converting the number into a string? The current data type is a float.

推荐答案

尝试一下

   SELECT CONCAT(a.fa_rate * 100 , '%') as rate_percent
   FROM accounts a;

这篇关于MySQL:将小数转换为视图内的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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