Truncate decimal places In one finance application I'm working on, the requirements call that I truncate a decimal value at certain number of places and not round.

Example: 11.685 truncated to 2 decimal places should be 11.68

I wrote this extension method, but was wondering if someone knew of an easier way.

public static class DecimalExtentsions
{
    public static decimal TruncateDecimalPlaces(this decimal val, int places)
    {
        if (places &lt;= 0)
            return Math.Truncate(val);

        var dv = Math.Pow(10, places);
        decimal part = (val % 1) * Convert.ToDecimal(dv);
        val -= (part % 1) / Convert.ToDecimal(dv);
        return val;
    }
}
One can use Math.Round() to truncate a number by removing 0.5 / 10 ^ places and then rounding

e.g 
     11.685 to 2 places

Math.Round(11.685 - 0.005, 2)  


The following seems to do the job

public static class NumberExtensions {
    public static decimal TruncateDecimalPlaces(this decimal val, int places) {
        if (places &lt; 0) {
            throw new ArgumentException("places");
        }
        return Math.Round(val - Convert.ToDecimal((0.5 / Math.Pow(10, places))), places);
    }
}



[TestMethod]
public void TruncateToPlaces() {

    Assert.AreEqual(10.665m, 10.6651M.TruncateDecimalPlaces( 3));
    Assert.AreEqual(10.665m, 10.6653M.TruncateDecimalPlaces( 3));
    Assert.AreEqual(10.665m, 10.6655M.TruncateDecimalPlaces( 3));
    Assert.AreEqual(10.665m, 10.6657M.TruncateDecimalPlaces( 3));
    Assert.AreEqual(10.665m, 10.665789M.TruncateDecimalPlaces( 3));
    Assert.AreEqual(10.665m, 10.66599999M.TruncateDecimalPlaces( 3));

    Assert.AreEqual(10m, 10.66599999M.TruncateDecimalPlaces( 0));
    Assert.AreEqual(10.6m, 10.66599999M.TruncateDecimalPlaces( 1));
    Assert.AreEqual(10.66m, 10.66599999M.TruncateDecimalPlaces( 2));
    Assert.AreEqual(10.665m, 10.66599999M.TruncateDecimalPlaces( 3));
    Assert.AreEqual(10.6659m, 10.66599999M.TruncateDecimalPlaces( 4));

}