Search code examples
sqlclickhouse

Display trailing zero on conversion using round function in SQL Clickhouse query


Whenever I use the round function, I get an integer value instead of a float.

For example when I run the below code

SELECT ROUND(12.99, 1)

I get 13 instead of 13.0.

What function can I try to get the answer I want?


Solution

  • Use toDecimalString...

    Converts a numeric value to String with the number of fractional digits in the output specified by the user.

    Returned value: Value represented as String with given number of fractional digits (scale). The number is rounded up or down according to common arithmetics in case requested scale is smaller than original number's scale.

    select toDecimalString(12.99, 1)
    
    Output: 13.0
    

    As you noted, the round function will ignore the zero and display as integer.