0

I am inserting a simple object into a database, using Linq2Sql (yes, yes, I will change to EF someday soon).

This object has a decimal value. When I debug, I can see the value of price is 6.8 .

However, when I insert into the database, the value is 7. The datatype of the field is decimal(18, 0) .

If it helps, I think it mgiht be because I am on a Danish computer, and the rounding char is "," and not ".".

My inserting code:

var order = new PlacedOrder()
{
    DateCreated = DateTime.Now,
    UserId = userid,
    PaymentInfo = paymentInfoId,
    ShippingInfo = shippingInfoId,
    OrderState =orderState.ToString(),
    PaymentMethod = paymentMethod.ToString(),
    Email = email,
    Phone = phone,
    PdfFilePath = pdfPath,
    Price = price,
    PriceVat = vat
};

db.PlacedOrders.InsertOnSubmit(order);
db.SubmitChanges();

Any ideas?

Noctis
  • 11,507
  • 3
  • 43
  • 82
Lars Holdgaard
  • 9,496
  • 26
  • 102
  • 182
  • possible duplicate of [How to store decimal values in SQL Server?](http://stackoverflow.com/questions/813287/how-to-store-decimal-values-in-sql-server) – Noctis Nov 16 '13 at 08:08

1 Answers1

2

Change the datatype from decimal(18, 0) to decimal(18, 2) to store values upto 2 decimal places, or `decimal(n,m)' for n precisions with m decimal points.

Because currently datatype is decimal(18, 0) , the decimal values are not stored in DB.

Tilak
  • 30,108
  • 19
  • 83
  • 131