I have a table with two decimal(18,0) fields.
我有一个包含两个十进制(18,0)字段的表。
I am inserting into this table, two decimal values. For example, 1.11
我在这个表中插入了两个十进制值。例如,1.11
When I select from the table (with no casts), I get 1.
当我从桌子中选择(没有演员表)时,我得到1。
I'm losing all percision and I have no clue why.
我失去了所有的优点,我不知道为什么。
insert into TEST values (153, 'test', 'test', 1, 1, 1.11, 1.11)
插入TEST值(153,'test','test',1,1,1.11,1.11)
Select * from TEST and they are 1 and 1 instead of 1.11,1.11
从TEST中选择*,它们是1和1而不是1.11,1.11
Any Ideas?
4 个解决方案
#1
When you declare a field as decimal(18,0), you are saying that you want 0 digits of precision after the decimal point. You're going to want to define those columns as decimal(18,2) (or however many digits of precision you desire) in order to maintain a value of 1.11.
当您将字段声明为十进制(18,0)时,表示您希望小数点后的精度为0位数。您将要将这些列定义为十进制(18,2)(或者您需要的精度数字),以保持值1.11。
Refer to the MSDN page on decimal and numeric types for the grisly details.
有关可怕的详细信息,请参阅十进制和数字类型的MSDN页面。
#2
Define the Precision to Decimal every time else it stores only int values not Decimal values
每次存储仅为int值而不是Decimal值时,将Precision定义为Decimal
#3
Try changing to type decimal(9,2)
尝试更改为十进制类型(9,2)
#4
Maybe try creating the columns as
也许尝试创建列
decimal(18,2)
#1
When you declare a field as decimal(18,0), you are saying that you want 0 digits of precision after the decimal point. You're going to want to define those columns as decimal(18,2) (or however many digits of precision you desire) in order to maintain a value of 1.11.
当您将字段声明为十进制(18,0)时,表示您希望小数点后的精度为0位数。您将要将这些列定义为十进制(18,2)(或者您需要的精度数字),以保持值1.11。
Refer to the MSDN page on decimal and numeric types for the grisly details.
有关可怕的详细信息,请参阅十进制和数字类型的MSDN页面。
#2
Define the Precision to Decimal every time else it stores only int values not Decimal values
每次存储仅为int值而不是Decimal值时,将Precision定义为Decimal
#3
Try changing to type decimal(9,2)
尝试更改为十进制类型(9,2)
#4
Maybe try creating the columns as
也许尝试创建列
decimal(18,2)