1

I am using a non en-US culture which is for Brazil (pt-BR). They use a comma for decimal separator. But When I try to serialize json and send it to javascript using the function below I get the numbers represented with period instead of comma.

var mydata = new { name="abc", value= 12.22};
JsonSerializerSettings settings = new JsonSerializerSettings() { Culture= new CultureInfo("pt-BR")};
JsonConvert.SerializeObject(mydata, settings)

I was expecting the value to go as 12,22(which is the brazil) instead of 12.22.

Does any one know what I have to do to make sure the serializer converts decimals based on the culture i give it.

Helen Araya
  • 1,886
  • 3
  • 28
  • 54
  • 1
    A number in JSON always uses `.` as a decimal separator. If you created "JSON" that used `,` instead, it would be invalid and other JSON processing tools would reject it. JSON is meant as a data interchange format between software programs; how the number should be displayed to an end user is outside of its scope. – user5090812 Oct 07 '16 at 15:19
  • 3
    The question already has an answer here: http://stackoverflow.com/questions/4721143/how-to-localize-when-json-serializing – Cristi Pufu Oct 07 '16 at 15:19
  • @user5090812 so why does the SerializeObject method accept culture as a second parameter if it is not doing anything? – Helen Araya Oct 07 '16 at 15:20
  • @AmeteBlessed - `JsonSerializer.Culture` is used for formatting values whose format is not specified explicitly in the [standard](http://www.json.org/), specifically `DateTime` and `DateTimeOffset`. – dbc Oct 07 '16 at 16:35

0 Answers0