C# Math Truncate(Decimal)
Description
Math Truncate(Decimal)
calculates the integral part
of a specified decimal number.
Syntax
Math.Truncate(Decimal)
has the following syntax.
public static decimal Truncate(
decimal d
)
Parameters
Math.Truncate(Decimal)
has the following parameters.
d
- A number to truncate.
Returns
Math.Truncate(Decimal)
method returns The integral part of d; that is, the number that remains after any fractional
digits have been discarded.
Example
The following example calls the Truncate(Decimal) method to truncate both a positive and a negative Decimal value.
using System;/*w w w . j a va2 s . c om*/
public class MainClass{
public static void Main(String[] argv){
decimal decimalNumber = 32.7865m;
Console.WriteLine(Math.Truncate(decimalNumber));
decimalNumber = -32.9012m;
Console.WriteLine(Math.Truncate(decimalNumber));
}
}
The code above generates the following result.