Controlling the amount of decimal places on fulltext search relevance score?
-
14-01-2021 - |
Question
I recall doing this before but I just can't remember how I did it, so was wondering if somebody could please enlighten me?
By default you usually get scores such as 14.9236183166504
for example; how can I trim that to just 2 decimal points or none at all?
Solution
The score is just a floating point number so you can use round
; for example, if you want two decimal places:
select round(match(x) against('y'), 2) as n from ...
and if you want none:
select round(match(x) against('y')) as n from ...
There's also floor
and ceil
if you're looking for integers on either side of the score or truncate
if you want to truncate the floating point value rather than round it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow