0

I have a problem calculating from double to string when I have a sum of a list. When the language setting is changed, I've tried using InvariantCulture but I've not managed to get it to work. Does anyone have any tips on how to process this?

Code looks like:

List<string> Moms_F = new List<string>();
double tot_Moms_F = Moms_F.Sum(x => Convert.ToDouble(x));
AssignControls(GetControls(wordDoc, "tot_Moms_F"), tot_Moms_F.ToString());

What I tried to to was

            CultureInfo ci;

            ci = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            ci.NumberFormat.NumberDecimalSeparator = ".";
            ci.NumberFormat.NumberGroupSeparator = ".";

and then adding

double tot_Moms_F = Moms_F.Sum(x => Convert.ToDouble(ci));

but I then get the error : Unable to cast object of type 'System.Globalization.CultureInfo' to type 'System.IConvertible'.

Does anyone have a good idea?

Wookoai
  • 47
  • 1
  • 8

1 Answers1

0

Solved it like this if anyone stumbles accross this issue and has the same problem:

CultureInfo ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
                ci.NumberFormat.CurrencyDecimalSeparator = ".";
float tot_Moms_F = Moms_F.Sum(x => float.Parse(x,NumberStyles.Any, ci));

One thing to note tough is that the printed value is , instead of . something too lokinto

Wookoai
  • 47
  • 1
  • 8