Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

JSON formatter and Localization settings

$
0
0

Hi

In my project I`ve set my localization options as follows:

            var dtf = new DateTimeFormatInfo
            {
                ShortDatePattern = "dd.MM.yyyy",
                LongDatePattern = "dd.MM.yyyy HH:mm",
                ShortTimePattern = "HH:mm",
                LongTimePattern = "HH:mm"
            };
            var nf = new NumberFormatInfo
            {
                CurrencyDecimalSeparator = ",",
                CurrencyGroupSeparator = ".",
                NumberDecimalSeparator = ",",
                NumberGroupSeparator = ".",
                NumberDecimalDigits = 2
            };

            var supportedCultures = new[]
{
                      new CultureInfo("en-US") { DateTimeFormat = dtf, NumberFormat = nf },
                      new CultureInfo("en-GB") { DateTimeFormat = dtf, NumberFormat = nf },
                      new CultureInfo("en") { DateTimeFormat = dtf, NumberFormat = nf },
                      new CultureInfo("pl-PL") { DateTimeFormat = dtf, NumberFormat = nf },
                      new CultureInfo("pl") { DateTimeFormat = dtf, NumberFormat = nf }
            };

            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("en-US"),
                SupportedCultures = supportedCultures,
                SupportedUICultures = supportedCultures
            });

However when I try to get some data through my API controller (with Accept-Language set to pl-PL) I get the following JSON result (only one decimal digit and dot instead of coma as a decimal separator):

"netValue": 120,"grossValueAdded": 147.6,

How to force my app to present JSON data in the correct format like this?

"netValue": 120,00,"grossValueAdded": 147,60,

Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>