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 b开发者_Python百科ecause 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 ?
You need to parse the string into a decimal
type, like this:
g.Sum(Function(p) Decimal.Parse(p!Valoare))
精彩评论