Sql Server Decimal(30,10) losing last 2 decimals

前端 未结 2 1465
北荒
北荒 2020-12-09 19:21

When 2 decimal(30,10) numbers are divided in Sql Server 05, 2 last decimals seem to be getting lost (not even rounded off, simply truncated).

For example:

         


        
2条回答
  •  时光取名叫无心
    2020-12-09 19:53

    The maximum precision allowed in SQL Server is 38. You are using Decimal(30,10). The max value is 99,999,999,999,999,999,999.9999999999 if you divide this number by 0.000000001, you will end up with an even bigger number, so the resulting data type must be able to accommodate it. This causes you to lose some precision.

    Change your original data types to Decimal(20,10) and this problem does not occur.

    For full rules regarding data types (and how they are affected by math operations):

    Full rules here

提交回复
热议问题