代码之家  ›  专栏  ›  技术社区  ›  madlan

T-SQL四舍五入到小数点

  •  7
  • madlan  · 技术社区  · 14 年前

    如何将匹配百分比的结果四舍五入到小数点后两位(%)?

    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
    
    1 回复  |  直到 4 年前
        1
  •  17
  •   OMG Ponies    14 年前

    投射/转换结果:

    CAST((CAST(ftt.RANK as DECIMAL)/@topRank) AS DECIMAL(n,2)) as matchpercent,
    

    …在哪里 n