Decimal - Truncate
Calculates the integral part of a specified decimal number.
public static void Main() { decimal[] values = { 32.7865m, 7.03m, 7.64m, 0.12m, -0.12m, -7.1m, -7.6m, -32.9012m }; Console.WriteLine(" Value Truncate\n"); foreach (decimal value in values) { // C# Extension Method: Decimal - Truncate Console.WriteLine("{0,7} {1,16}", value, value.Truncate()); } }
View Source
using System; public static partial class Extensions { /// <summary> /// Calculates the integral part of a specified decimal number. /// </summary> /// <param name="d">A number to truncate.</param> /// <returns> /// The integral part of ; that is, the number that remains after any fractional digits have been discarded. /// </returns> public static Decimal Truncate(this Decimal d) { return Math.Truncate(d); } }