Appropriate datatype for holding percent values?

前端 未结 5 1685
夕颜
夕颜 2020-12-22 23:39

What is the best datatype for holding percent values ranging from 0.00% to 100.00%?

5条回答
  •  -上瘾入骨i
    2020-12-22 23:52

    Use numeric(n,n) where n has enough resolution to round to 1.00. For instance:

    declare @discount numeric(9,9)
        , @quantity int
    select @discount = 0.999999999
        , @quantity = 10000
    
    select convert(money, @discount * @quantity)
    

提交回复
热议问题