如何在没有php的情况下将数字格式化为货币值?

时间:2017-11-16 10:18:38

标签: mysql

我的mySQL数据库13148.70中有一个值。我想将其转换为货币格式:

$data = $db->query('SELECT *, ROUND((price), 2) AS price FROM data')->fetchAll(PDO::FETCH_ASSOC); 

结果是:

13148.70

但我需要13 148,70 €

3 个答案:

答案 0 :(得分:1)

您可以在php中使用函数money-format:money-format

你在mysql中可以做的就是:

SELECT *, REPLACE(REPLACE(CONCAT(FORMAT(price, 2)," €"), ",", " "),".",",") AS price FROM data

答案 1 :(得分:1)

<强>语法

number_format(number,decimals,decimalpoint,separator)

所以在你的情况下:

$data = number_format($data, 2, ",", " ");

更多信息:number_format

答案 2 :(得分:0)

请参阅https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_format

select REPLACE(CONCAT(FORMAT(price,2,'de_DE')," €"),"."," ") from data;