Decimal.Truncate() Method in C#
This method is used to get the integral digits of the specified Decimal by discarding any fractional digits. This method rounds the specified value to the nearest whole number by removing the digits after the decimal point.
Syntax: public static decimal Truncate (decimal d);
Here, d is the decimal number which is to be truncated.Return Value: It returns the result of d rounded toward zero, to the nearest whole number.
Example:
// C# program to demonstrate the // Decimal.Truncate(Decimal) Method using System; class GFG { // Main Method public static void Main() { try { // Taking decimal variables // having fractional part Decimal dec1 = 214748.78549M; Decimal dec2 = 21458565.2996m; // using Decimal.Truncate(Decimal) Method Decimal val1 = Decimal.Truncate(dec1); // using Decimal.Truncate(Decimal) Method Decimal val2 = Decimal.Truncate(dec2); // Printing the Integral part only Console.WriteLine("The integral part of "+ "dec1 is: {0}", val1); Console.WriteLine("The integral part of "+ "dec2 is: {0}", val2); } catch (OverflowException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } |
The integral part of dec1 is: 214748 The integral part of dec2 is: 21458565
Reference:
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | IndexOfAny() Method
- C# | CompareOrdinal() Method
- C# | Uri.FromHex() Method
- C# | Uri.MakeRelativeUri(Uri) Method
- C# | Replace() Method
- C# | Method Overloading
- C# | Dictionary.Add() Method
- C# | Math.Log() Method
- C# | Insert() Method
- DateTime.Add() Method in C#
- C# | Method Overriding
- C# | Math.Pow() Method
- C# | Uri.GetHashCode() Method
- Main Method in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



