问题
I'm trying to get from an decimal(13.6) value to currency in EURO's
I'm getting this as result right now:
╔══════════════╦═════════╗
║ total ║ Date ║
╠══════════════╬═════════╣
║8887616.500000║ 2017 ║
╚══════════════╩═════════╝
What I want is something like this one:
╔══════════════╦═════════╗
║ total ║ Date ║
╠══════════════╬═════════╣
║€8,887.616.50 ║ 2017 ║
╚══════════════╩═════════╝
Or this one:
╔══════════════╦═════════╗
║ total ║ Date ║
╠══════════════╬═════════╣
║ €M8,9 ║ 2017 ║
╚══════════════╩═════════╝
I did try to convert from decimal but had no luck with that
SELECT SUM(totalExcl) AS total, DATE_FORMAT(date_add, '%Y') AS 'Date'
FROM ex.ps_oxo_quotation
WHERE saleType IN ('IEW' , 'As', 'Pr')
AND date_add >= '2017-01-01 00:00:00'
GROUP BY 'Date'
ORDER BY 'Date' DESC
回答1:
This will give you a sum formatted in Euro:
SELECT CONCAT('€', FORMAT(SUM(totalExcl), 2, 'de_DE')) AS total
Will show: €8.890.905,86
The other requested alternative:
SELECT CONCAT('€M', FORMAT((SUM(totalExcl)/1000000), 1, 'de_DE')) AS total
Will show: €M8,9
Note that this example will show the sum according to standards (LOCALE de_DE), and not with the exact format you have requested, that have mixed dots "." and commas "," in a non standard way. This could easily be fixed with some string manipulation if you really must format the sum that way.
来源:https://stackoverflow.com/questions/42676124/mysql-from-decimal13-6-to-currency