- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Decimal.Truncate() Method in C#
The Decimal.Truncate() method in C# is used to return the integral digits of the specified Decimal. Remember, any fractional digits are discarded.
Syntax
Following is the syntax −
public static decimal Truncate (decimal val);
Above, Val is the decimal number to truncate.
Example
Let us now see an example to implement the Decimal.Truncate() method −
using System; public class Demo { public static void Main(){ Decimal val = 6576.876m; Console.WriteLine("Decimal value = "+val); ulong res = Decimal.ToUInt64(val); Console.WriteLine("64-bit unsigned integer = "+res); Decimal val2 = Decimal.Truncate(val); Console.WriteLine("Integral digits of the decimal = "+val2); } }
Output
This will produce the following output −
Decimal value = 6576.876 64-bit unsigned integer = 6576 Integral digits of the decimal = 6576
Example
Let us now see another example to implement the Decimal.Truncate() method −
using System; public class Demo { public static void Main(){ Decimal val = 28676.935m; Console.WriteLine("Decimal value = "+val); Decimal val2 = Decimal.Truncate(val); Console.WriteLine("Integral digits of the decimal = "+val2); } }
Output
This will produce the following output −
Decimal value = 28676.935 Integral digits of the decimal = 28676
Advertisements