- 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
Math.Truncate() Method in C#
The Math.Truncate() method in C# is used to compute an integral part of a number, which is Double or Decimal.
Syntax
public static decimal Truncate(decimal val1) public static double Truncate(double val2)
Above, there are two syntaxes. The value val1 is the decimal number to truncate, whereas val2 is the double number to truncate.
Example
Let us now see an example to implement Math.Truncate() method −
using System; public class Demo { public static void Main(){ Decimal val1 = 25.46467m; Decimal val2 = 45.9989m; Decimal val3 = 678.325m; Console.WriteLine(Math.Truncate(val1)); Console.WriteLine(Math.Truncate(val2)); Console.WriteLine(Math.Truncate(val3)); } }
Output
This will produce the following output −
25 45 678
Example
Let us see another example to implement Math.Truncate() method −
using System; public class Demo { public static void Main(){ Double val1 = 95.86467; Double val2 = 25.11; Double val3 = 878.325; Console.WriteLine(Math.Truncate(val1)); Console.WriteLine(Math.Truncate(val2)); Console.WriteLine(Math.Truncate(val3)); } }
Output
This will produce the following output −
95 25 878
Advertisements