I had a very strange problem of removing fractional part of decimal while converting between decimal
and decimal?
My Code (the data is fetched from database using EntityFramework):
var rs = from s in db.SalesDocHeader
select new SalesTransaction
{
SalesDocHeaderId = s.id,
TotalGrossAmount = s.total_gross ?? 0M
};
Definition of SalesTransaction class:
public class SalesTransaction
{
public int SalesDocHeaderId { get; set; }
public decimal TotalGrossAmount { get; set; }
}
Definition of SalesDocHeader class (generated by Entity Framework).
public partial class SalesDocHeader
{
public int id { get; set; }
public Nullable<decimal> total_gross { get; set; }
}
Whenever the above code is executed TotalGrossAmount is rounded to largest previous integer. So if s.total_gross = 32.9, TotalGrossAmount becomes 32, 64.3 becomes 64 and so on.
How can I prevent this problem?