如何将matchpercent的结果舍入到两位小数(%)? 我正在使用以下内容返回一些结果:
DECLARE @topRank int
set @topRank=(SELECT MAX(RANK) FROM
FREETEXTTABLE(titles, notes, 'recipe cuisine', 1))
SELECT
ftt.RANK,
(CAST(ftt.RANK as DECIMAL)/@topRank) as matchpercent, --Round this
titles.title_id,
titles.title
FROM Titles
INNER JOIN
FREETEXTTABLE(titles, notes, 'recipe cuisine') as ftt
ON
ftt.[KEY]=titles.title_id
ORDER BY ftt.RANK DESC
答案 0 :(得分:17)
CAST / CONVERT结果:
CAST((CAST(ftt.RANK as DECIMAL)/@topRank) AS DECIMAL(n,2)) as matchpercent,
...其中n
是一个足够大的数字,不会截断小数点的左边。也就是说,如果使用“123.456”,则需要使用DECIMAL(7,2),因为总长度为7位。