1

One of my software's functions is to convert numeric strings into double datatype. I want to explicitly indicate the use of period (.) as a decimal point. Thus, no matter the language settings of the user's system, it will correctly read a period-separated decimal. I believe the solution is to use the IFormatProvider argument in the Convert.ToDouble() function. I am unsure how to do this.

Example: String: "3.14" Double: 3.14

Joe Sisk
  • 602
  • 1
  • 8
  • 17

2 Answers2

3

Use CultureInfo.InvariantCulture while parsing.

double d = double.Parse("3.14", CultureInfo.InvariantCulture);

See: CultureInfo.InvariantCulture Property

The invariant culture is culture-insensitive; it is associated with the English language but not with any country/region.

Habib
  • 219,104
  • 29
  • 407
  • 436
1
double.Parse(yourString, CultureInfo.InvariantCulture)

Edit: or see this question

Community
  • 1
  • 1
jle
  • 9,316
  • 5
  • 48
  • 67