views:

343

answers:

1

I am having some trouble with a LINQ to dataset query. I have the problem that data is returned to the dataset as a double and could be null. When I get the data into my LINQ query it truncates to one decimal place. I am wondering if anyone can tell me the best way to set the precision so that it retains two decimal places? I have tried using 'Double?' but when I do this I get an invalid cast exception. Here is a sample of my L2D query:

Dim query = _
From bb In bbdata.AsEnumerable(), _
        ab In abdata.AsEnumerable() _
    Where (bb.Field(Of String)("bbID").ToUpper.Trim() = _
          ab.Field(Of String)("abID").ToUpper.Trim()) _
Order By _
            bb.Field(Of String)("Sequence") Descending, _
            bb.Field(Of String)("Name") Ascending, _
            bb.Field(Of String)("bbID").ToUpper.Trim() Ascending, _
            ab.Field(Of Decimal?)("TWO_DECIMAL_DIGIT_DOUBLE") Descending _
Select New With _
{ _
    .bbID = bb.Field(Of String)("bbID"), _
    .Weight = ab.Field(Of Decimal?)("TWO_DECIMAL_DIGIT_DOUBLE"), _
    .Sequence = bb.Field(Of String)("Sequence"), _
    .Name = bb.Field(Of String)("Name"), _
}

When I run this, the Double is truncated to one decimal and needs to be of precision where there are 2 decimal places. Any help is greatly appreciated.

A: 

Maybe it's because the Weight property rounds the value with a precision of one decimal place? I don't know what else could cause this behavior...

Meta-Knight
One of the datasets has a precision of one decimal whereas the other has a precision of two decimals. I was confused because it is truncated and not rounded, so I didn't think about the fact that it might be an issue of least precision. I'm so new to linq that I just assumed it must be a linq issue. Crap. Thank you for your help!
Brian