Why does SQL Server round off results of dividing two integers?

后端 未结 6 1758
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 17:22

I have a table with a smallint column that contains percentages as whole numbers (i.e., 50, 75, 85, etc.)

When I divide this column by 100, as in

SEL         


        
6条回答
  •  借酒劲吻你
    2020-12-03 17:33

    When you are using /(Divide) operator it

    Returns the data type of the argument with the higher precedence.

    and

    If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.

    So, you need to cast at least one of the operands to appropriate type: decimal and numeric or float or real.

提交回复
热议问题