Archive of

A neat way to remove trailing zeros from a decimal number in C#

We can get unexpected trailing zeros when we serialzie an object with decimal properties, normally it will not hurt. However, it does hurt when we want to compare two objects by serializing them to JSON string. I tried a few solutions and finally find the following one is the best.

public static decimal Normalize(this decimal value)
    return value/1.000000000000000000000000000000000m;