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.

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.

The example value in the database: 0.46

What I’d like to have returned: 46%

Relevant portions of current query:

SELECT CONCAT(a.fa_rate, ‘%’) as rate_percent

FROM accounts a;

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.

解决方案

try this

SELECT CONCAT(a.fa_rate * 100 , ‘%’) as rate_percent

FROM accounts a;