3

When editing the fields from within Visual Studio 2010, I change the value to 0,01.

enter image description here

When comminiting the changes by cycling to the end of the row, it turns into a 0.

enter image description here

Any ideas why this happens? I need it to save 0,01 as the value. The same problem happens with the RegularCost field. I need to save something like 299,45 to it, and it rounds off.

Here's the SQL:

create table Auction
(
AuctionId int primary key identity(1,1),
ProductId int foreign key references Product(ProductId),
AuctionCategoryId int foreign key references AuctionCategory(AuctionCategoryId),
SerialNumber nvarchar(1024),
StartTime datetime,
EndTime datetime,
AvailableForBuyNow bit,
BuyNowCost decimal,
LanceCost decimal,
ClosingLanceCount int,
WonByUser int,
RegularCost decimal
)
Only Bolivian Here
  • 35,719
  • 63
  • 161
  • 257

2 Answers2

5

You need to define it as

decimal(12,2)

This specifies the precision (12) and the scale (2). If you wanted 4 decimal places, you could do decimal(12,4).

The default value is 0 for the places right of a decimal.

http://msdn.microsoft.com/en-us/library/ms187746.aspx

taylonr
  • 10,732
  • 5
  • 37
  • 66
1

Try specifying precision and scale like so

LanceCost decimal(10,2)

or use the money type:

LanceCost money
canon
  • 40,609
  • 10
  • 73
  • 97
  • Spot on with the decimal recommendation.You should avoid the money type 99.99999% of the time, though. http://stackoverflow.com/questions/582797/should-you-choose-the-money-or-decimalx-y-datatypes-in-sql-server – Kenneth Aug 29 '11 at 20:28