Convert string with German culture format to double using JsonConvert

828 Views Asked by At

I need to convert German format currency in a JSON (value may be negative or positive) to Double, I am able to do it using double.parse and specifying NumberStyle, something like below

CultureInfo culture = CultureInfo.CreateSpecificCulture("de-DE");
var convertedValue = double.Parse("2.664.221,01-", NumberStyles.Currency, culture);

But, there are multiple properties that require conversion and I am looking for a better way to do it instead of doing parsing for each property. I am thinking of using JsonSerializerSettings and then use Json Convert. But could not find a way to specify styles in JsonSerializerSettings.

Is there a better way to handle this?

var settings = new JsonSerializerSettings()
                    {
                        Culture = new CultureInfo("de-DE"),
                        //NumberStyle = currency 
                    };

                    var res = JsonConvert.DeserializeObject<MyObject>(json, settings);
0

There are 0 best solutions below