clickhouse – getting n most significant digits of a number

i’m testing some wild idea of finding matches in quite a large dataset. part of the problem is that scaling of input is unknown, 123 might be correct match for 1.23 or for 12.3.

here’s an expression that returns me n=4 most significant digits of each float from the input array:

SELECT arrayMap(x -> if(x = 0, 0, floor(pow(10, 3 - floor(log10(abs(x)))) * abs(x)) * sign(x)), [10, 23, 11.1, 3783.3, -0.3213, 0, 9831982732196.318]) AS res

β”Œβ”€res────────────────────────────────┐
β”‚ [1000,2300,1110,3783,-3212,0,9831] β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Leave a Reply

Your email address will not be published. Required fields are marked *

 

(Spamcheck Enabled)