简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM