Convert string to int or double, decimal

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,
What's the right way to do it?
Works, but maybe not the best way.
string t2 = countToAnaylse.Replace(".", "").Replace(",", "");
Nothing works.

My trials.

// -----------------------------------------------------------

string countToAnaylse = "7.765";

int helpCountMustBe = 0;

//CultureInfo.InvariantCulture
// helpCountMustBe = int.Parse(countToAnaylse, new CultureInfo("de-DE"));
NumberFormatInfo num = new NumberFormatInfo();
num.NumberDecimalSeparator = ",";
num.NumberGroupSeparator = "-"; // ".";
string t1 = String.Format(num, "{0}", countToAnaylse);
string t2 = countToAnaylse.Replace(".", "").Replace(",", "");

//try
//{
// helpCountMustBe = int.Parse(countToAnaylse, CultureInfo.InvariantCulture);
//}
//catch (Exception eCult)
//{
// Trace.Writeline($"{LOG}[Scan] '{eCult.Message}' ");
//}

//if (helpCountMustBe == 0)
//{
// helpCountMustBe = int.Parse(countToAnaylse, new CultureInfo("de-DE"));
//}
1492217.jpg
Best regards Markus

Continue reading...
 
Back
Top