Note that, obviously, one of Decimal's claims to fame is that it considers trailing zeros as significant, so serializing /should/ record those details.
If you want to adjust that, use Decimal.Round(value, 2), but note that this does not add trailing zeros, only removes extras. -- Regards, Mark Hurd, B.Sc.(Ma.)(Hons.) On 11 August 2013 14:32, Corneliu I. Tusnea <corne...@acorns.com.au> 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 >