While decimal.Parse () is the method you are looking for, you will have to provide it with a bit more information. It will not automatically choose between the three formats that you give, you will need to specify which format you expect (in the form of IFormatProvider). Note that even with IFormatProvider, I donβt think that β50085β will be properly retracted.
The only thing I see is that from your examples you can see that you always expect two decimal places of precision. If so, you can remove all periods and commas, and then divide them by 100.
Maybe something like:
public decimal? CustomParse(string incomingValue) { decimal val; if (!decimal.TryParse(incomingValue.Replace(",", "").Replace(".", ""), NumberStyles.Number, CultureInfo.InvariantCulture, out val)) return null; return val / 100; }
source share