开发者

linq sum string as decimal

开发者 https://www.devze.com 2022-12-21 00:53 出处:网络
I have the following LINQ : Dim q = From p In ds_raport.Tables(1) _ Group p By p!Cod_Prj Into g = Group _

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

精彩评论

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

关注公众号