I download one program that read file and then parse double values from String to Double. But I get an exception because this file contains numbers with '.' separator, but there is ',' in my culture. How can I set culture explicitly?
+6
A:
You would use the Parse
overload that accepts an IformatProvider
.
Double.Parse("23.56", new CultureInfo("..."))
If you don't know the culture used to write the file you create a NumberFormatInfo
and configure it as you like:
var nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
var d = Double.Parse("23.56", nfi);
João Angelo
2010-04-22 15:54:35
A:
Also usable:
double.Parse((""+s).Replace(",","."), System.Globalization.CultureInfo.InvariantCulture)
Ugly as hell, but that's .Net... :)
AareP
2010-04-22 16:14:22