WingMan20-10
WingMan20-10

Reputation: 3734

I need convert a decimal to int in a linq statement

I have this linq statement.

var sum = from l in list
select new
{
    Sum = (l.sum + .005) * 1000
};

this line won't work:

Sum = (l.sum + .005) * 1000 

because sum is a decimal.

I would like to use System.Data.Objects.SqlClient.SqlFunctions but there is no Convert or Cast...

Is there any way i can do this?

Upvotes: 0

Views: 1723

Answers (1)

Enigmativity
Enigmativity

Reputation: 117010

As far as I can see the issue is that 0.005 is a double and not that l.sum is a decimal. Your code should work if you change it like this:

var sum = from l in list
select new
{
    Sum = (l.sum + .005M) * 1000
};

Note the M after .005

Upvotes: 3

Related Questions