如何将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
转换/转换结果:
CAST((CAST(ftt.RANK as DECIMAL)/@topRank) AS DECIMAL(n,2)) as matchpercent,
…这里n的数字足够大,不能截断小数点左边。也就是说,如果使用“ 123.456”,则由于总长度为7位,因此需要使用DECIMAL(7,2)。
n