I'm trying to store a value with three decimals in an MsSQL
database, but for some reason the third decimal is always changed to a 0
. I can't figure out why.
The project was created by somebody else with Entity Framework code first v4.0.30319
and it created a column in the database [Amount] [decimal](18, 2) NULL
. I have manually changed the database to [Amount] [decimal](18, 3) NULL
In the code:
var _yourbid = form["YourBid"]; // value = 10.123
decimal yourbid;
if (decimal.TryParse(_yourbid, out yourbid))
{
Bid b = new Bid();
b.Amount = yourbid;
//yourbid = 10.123
//b.Amount = 10.123
Db.Bids.Add(b);
Db.Save();
//in database is 10.120
}
Now I expected that the code first
somewhere declared the decimal to have a scale of 2, but I couldn't find anything. I checked the options listed in Decimal precision and scale in EF Code First but it's not used.
There isn't a trigger on the database that might be changing it either. I can put in the right value directly from SQL
I must be missing something obvious, but I hope you can point me in the right direction.