开发者

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))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜