Hi,
I have a collection of type string, which consists of integers and decimals I am trying to add them by
stringSum= listvalues.sum(Function(s) cdbl(s)),
but I am getting error–> conversion from string to type double is not valid.
How can I add them, I need sum of list.
Hi @Swetha_MN ,
Could you let us know what are the values in the list that you are trying to find the sum value ?
14,341,1.01,12,345,3,456.34
I’m able to get the sum without any issue
Check below
Also check if your list is containing any null values or string values
Hope this may help you
Thanks
You have taken only integers, my list contains decimals also ,. (14,341),(1.01),(12,345),(3,456.34)
See here there are 14,341 which is considering as String, so you need to replace that
Hope this will help you
Thanks
If the above suggestions still do not work, Do provide us with the Screenshot of the data used in the List by performing Debug, it seems the data has some issues.
We should be able to get the Sum even if there are decimals and whole number values in the list.
Let us know if you could provide the Screenshot of the Data in Debug Mode.
maybe the discussion can be short cut.
Above we do see that initial Sum and CDBL is working (assumption valid strings, not empty strings)
-
when default formats are to expect: comma is group seperator, dot is decimal seperator
THEN we can use CDBL method -
when a local format like dot is group seperator, comma is decimal seperator is used
THEN we would parse it e.g. with:
Double.Parse(TheNumberString, System.Globlaization.CultureInfo.CreateSpecificCulture(“de-DE”)) or other culture matching the format
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.