T-SQL Round to decimal places

前端 未结 1 1967
無奈伤痛
無奈伤痛 2021-01-05 09:37

How do I round the result of matchpercent to two decimal places (%)? I\'m using the following to return some results:

DECLARE @topRank int
set @topRank=(SELE         


        
相关标签:
1条回答
  • 2021-01-05 10:04

    CAST/CONVERT the result:

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

    ...where n is a number large enough not to truncate left of the decimal point. That is to say, if you use "123.456", you need to use DECIMAL(7,2) because the total length is 7 digits.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题