Double - Truncate
Calculates the integral part of a specified double-precision floating-point number.
public static void Main() { double[] values = { 25653.25, 7883.75, 256, 64.0, 35.36, 8, 0, -7.6 }; Console.WriteLine(" Value Truncate\n"); foreach (double value in values) { // C# Extension Method: Double - 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 double-precision floating-point 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, or /// one of the values listed in the following table. Return value. /// </returns> public static Double Truncate(this Double d) { return Math.Truncate(d); } }