简体   繁体   English

SQL Server插入十进制,但选择Int

[英]SQL Server Inserting Decimal, but selecting Int

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) 插入测试值中(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? 有任何想法吗?

When you declare a field as decimal(18,0), you are saying that you want 0 digits of precision after the decimal point. 当您将一个字段声明为十进制(18,0)时,就是说您希望小数点后的精度为0位。 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. 您将需要将这些列定义为decimal(18,2)(或所需的精度位数),以保持值1.11。

Refer to the MSDN page on decimal and numeric types for the grisly details. 有关十进制和数字类型的详细信息,请参阅MSDN页面

每次将精度定义为十进制时,否则仅存储int值,不存储十进制值

尝试更改为十进制(9,2)类型

Maybe try creating the columns as 也许尝试创建列为

decimal(18,2) 十进制(18,2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM