

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
- Related Questions & Answers
- C# Truncate Method
- Java signum() method with Examples
- Java lang.Long.toBinaryString() method with Examples
- Java cbrt() method with Examples
- Java ceil() method with Examples
- Java sqrt() method with Examples
- Java floor() method with Examples
- Java toDegrees() method with Examples
- C# Stack.TrimExcess() Method with Examples
- C# Object.GetHashCode() Method with Examples
- C# Object.GetType() Method with Examples
- C# Queue.TrimExcess() Method with Examples
- jQuery not() method with Examples
- JavaScript removeEventListener() method with examples
- MathF.Tan() Method in C# with Examples
- MathF.Tanh() Method in C# with Examples
Advertisements