If you know that the string representation of the number uses comma as the decimal separator you can parse the value using a custom NumberFormatInfo
:
var number = "3,4589";
var numberFormatInfo = new NumberFormatInfo { NumberDecimalSeparator = "," };
var value = Decimal.Parse(number, numberFormatInfo);
You can also use an existing CultureInfo
for a culture that you know will work like pl-PL
but I think this is easier to understand.
If on the other hand the format of the number is 3.4589
you can simply use CultureInfo.InvariantCulture
which you can consider a kind of "default" culture based on en-US
:
var number = "3.4589";
var value = Decimal.Parse(number, CultureInfo.InvariantCulture);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…