Iulian
Iulian

Reputation: 1200

linq sum string as decimal

I have the following LINQ :

    Dim q = From p In ds_raport.Tables(1) _
      Group p By p!Cod_Prj Into g = Group _
      Select New With {g, .TotalVal = g.Sum(Function(p) p!Valoare)}

The problem is because column "valoare" is of type string ( i import this from a file that is not always properly formatted) my sum has no decimals.

So how can i make the sum to display decimals ?

Upvotes: 1

Views: 2637

Answers (1)

SLaks
SLaks

Reputation: 887453

You need to parse the string into a decimal type, like this:

g.Sum(Function(p) Decimal.Parse(p!Valoare))

Upvotes: 1

Related Questions