Search code examples
clickhouse

In clickhouse, how can I separate number by comma?


In clickhouse, how can I separate number by comma?

select toString(toDecimal64(roundBankers( 12321.121 ,  1 ),  1 ))

and returns 12,321.1 instead of 12321.1, thanks.


Solution

  • Such formatting to strings from numbers is not implemented.

    select formatReadableQuantity(roundBankers( 12321.121 ,  1 ));
    ┌─formatReadableQuantity(roundBankers(12321.121, 1))─┐
    │ 12.32 thousand                                     │
    └────────────────────────────────────────────────────┘
    
    SELECT concat(toString(intDiv(roundBankers(12321.121, 1) AS x, 1000)), ',', toString(x % 1000)) AS r
    ┌─r─────────────────────┐
    │ 12,321.10000000000036 │
    └───────────────────────┘