What will be the best way to include the result with dollar sign?
I was using something like CONCAT('£', SUM(Deposits)) AS TotalDeposits
but it seems not working.
What will be the best way to include the result with dollar sign?
I was using something like CONCAT('£', SUM(Deposits)) AS TotalDeposits
but it seems not working.
Copyright © 2021 Jogjafile Inc.
MySQL boasts a FORMAT() function for doing the number formatting part of this.
gets you the US and DE formatting. You have to put in the currency symbol yourself; MySQL's locale handling doesn't throw it in for you.
If you're dealing with other peoples' money, you may want to use a data type like
DECIMAL(20,2)
rather than aFLOAT
orDOUBLE
so you don't get floating-point-style arithmetic rounding errors in aggregate functions likeSUM()
.That all being said: wise programmers often handle this kind of formatting in their application programs rather than their databases, as @ADyson pointed out in his comment. That's because application programming languages have more complete locale handling than databases (at any rate MySQL) and you can control it better.