Home »
.Net »
C# Programs
C# - Math.Truncate() Method with Example
In this tutorial, we will learn about the C# Math.Truncate() method with its definition, usage, syntax, and example.
By Nidhi Last updated : March 29, 2023
C# Math.Truncate() Method
The Math.Truncate() method is used to return an integral part of the given number, this method is overloaded two times then the given number can be a double or decimal number.
Syntax
double Math.Truncate(double num);
decimal Math.Truncate(decimal num);
Parameter(s)
- num : it can be a double or decimal number according to an overloaded method.
Return Value
This method returns an integral part of a given number, it can be double or decimal according to an overloaded method.
C# Example of Math.Truncate() Method
The source code to demonstrate the use of Truncate() method of Math class is given below. The given program is compiled and executed successfully.
using System;
class Sample {
//Entry point of Program
static public void Main() {
decimal decNum = 123.4567m;
double dblNum = 123.4567;
Console.WriteLine("Demonstration of Truncate method: ");
Console.WriteLine(Math.Truncate(decNum));
Console.WriteLine(Math.Truncate(dblNum));
}
}
Output
Demonstration of Truncate method:
123
123
Press any key to continue . . .
C# Math Class Programs »