Looks like decimal.ToString("G0") will strip the zeros, so s1.ToString("G0") == s2.ToString("G0"). I don't know if you can make NewtonSoft do that though.

Note that this will fall back to scientific notation, so 0.0000000000000000000000001m.ToString("G0") == "1E-25".

Ben


On 11/08/2013 3:02 PM, Corneliu I. Tusnea wrote:
Hi,

Anyone working today?

How can I force the NewtonSoft Json Serializer to serialize two decimals the same way? decimal a = 1234.1200M; decimal b = 1234.12M;

|var  sa=  JsonConvert.SerializeObject(new  {  value=  a});
var  sb=  JsonConvert.SerializeObject(new  {value=  b});
Console.WriteLine(sa);
Console.WriteLine(sb);|

Results are: {"value":1234.1200} {"value":1234.12}

How can I force it to serialize them both with 4 decimals so the results are identical?

Even simpler, ignoring the serializer, how can I make sa.ToString() == sb.ToString() ?
The Json Serializer is only doing a simple .ToString() behind the scenes.

Regards,
Corneliu


Reply via email to