Search code examples
mysqlsumdecimalmysql-5.7decimal-point

MySQL decimal column SUM


I am using MySQL 5.7.22. I have decimal columns in my table. Decimal column values like 31355,20,30710,00. In the query when I get sum two values of the column, the result is without comma. But I need digits after comma. How can I do this? What is the problem?


Solution

  • mysql float use dot . instead of a comma, but if you want to get comma you can try to convert your result to string the use REPLACE function.

    Schema (MySQL v5.7)

    CREATE TABLE T(col DECIMAL(5, 2));
    
    INSERT INTO T VALUES (11.22)
    

    Query #1

    select REPLACE(cast(col as CHAR(50)),'.',',') 
    from T;
    
    | REPLACE(cast(col as CHAR(50)),'.',',') |
    | -------------------------------------- |
    | 11,22                                  |
    

    View on DB Fiddle