A SQL Column of type decimal rounds the number 0,01 to 0
When editing the fields from within Visual Studio 2010, I change the value to 0,01
.
When comminiting the changes by cycling to the end of the row, it turns into a 0.
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),
Aucti开发者_JS百科onCategoryId 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
)
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
Try specifying precision and scale like so
LanceCost decimal(10,2)
or use the money type:
LanceCost money
精彩评论