![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
MathF.Truncate() Method in C# with Examples
The MathF.Truncate() method in C# is used to calculate an integral part of a specified single number or single-precision floating-point number.
Syntax
Following is the syntax −
public static float Truncate (float val);
Above, Val is the specified number to be truncated
Example
Let us now see an example to implement the MathF.Truncate() method −
using System; public class Demo { public static void Main(){ float val1 = float.PositiveInfinity; float val2 = float.NegativeInfinity; Console.WriteLine("MathF.Truncate(val1) = "+MathF.Truncate(val1)); Console.WriteLine("MathF.Truncate(val2) = "+MathF.Truncate(val2)); } }
Output
This will produce the following output −
MathF.Truncate(val1) = Infinity MathF.Truncate(val2) = -Infinity
Example
Let us now see another example to implement the MathF.Truncate() method −
using System; public class Demo { public static void Main(){ float val1 = 76.8787f; float val2 = 4646.5656f; Console.WriteLine("MathF.Truncate(val1) = "+MathF.Truncate(val1)); Console.WriteLine("MathF.Truncate(val2) = "+MathF.Truncate(val2)); } }
Output
This will produce the following output −
MathF.Truncate(val1) = 76 MathF.Truncate(val2) = 4646
Advertisements