How can I print the integer part of a number with commas separating every three digits?

For example,

 12345    -> 12,345
 1234.567 -> 1,234.567

closed as off topic by Mark Storey-Smith, Jon Seigel, Marian, Max Vernon, Aaron Bertrand Apr 7 '13 at 18:41

Questions on Database Administrators Stack Exchange are expected to relate to database administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.


Use the FORMAT function, which works for floating point numbers as well as for integers:

Floating point numbers:

mysql> SELECT FORMAT(12332.123456, 4);
        -> '12,332.1235'
mysql> SELECT FORMAT(12332.1,4);
        -> '12,332.1000'
mysql> SELECT FORMAT(12332.2,0);
        -> '12,332'


mysql> SELECT FORMAT(12334, 0);
        -> 12,334

Not the answer you're looking for? Browse other questions tagged or ask your own question.